• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ ALIGN_SIZE函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ALIGN_SIZE函数的典型用法代码示例。如果您正苦于以下问题:C++ ALIGN_SIZE函数的具体用法?C++ ALIGN_SIZE怎么用?C++ ALIGN_SIZE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ALIGN_SIZE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: my_multi_malloc

void* my_multi_malloc(myf myFlags, ...)
{
  va_list args;
  char **ptr,*start,*res;
  size_t tot_length,length;
  DBUG_ENTER("my_multi_malloc");

  va_start(args,myFlags);
  tot_length=0;
  while ((ptr=va_arg(args, char **)))
  {
    length=va_arg(args,uint);
    tot_length+=ALIGN_SIZE(length);
  }
  va_end(args);

  if (!(start=(char *) my_malloc(tot_length,myFlags)))
    DBUG_RETURN(0); /* purecov: inspected */

  va_start(args,myFlags);
  res=start;
  while ((ptr=va_arg(args, char **)))
  {
    *ptr=res;
    length=va_arg(args,uint);
    res+=ALIGN_SIZE(length);
  }
  va_end(args);
  DBUG_RETURN((void*) start);
}
开发者ID:0x00xw,项目名称:mysql-2,代码行数:30,代码来源:mulalloc.c


示例2: request

/*
================
idHeap::Msize

  returns size of allocated memory block
  p	= pointer to memory block
  Notes:	size may not be the same as the size in the original
			allocation request (due to block alignment reasons).
================
*/
dword idHeap::Msize( void *p ) {

	if ( !p ) {
		return 0;
	}

#if USE_LIBC_MALLOC
	#ifdef _WIN32
		return _msize( p );
	#else
		return 0;
	#endif
#else
	switch( ((byte *)(p))[-1] ) {
		case SMALL_ALLOC: {
			return SMALL_ALIGN( ((byte *)(p))[-SMALL_HEADER_SIZE] * ALIGN );
		}
		case MEDIUM_ALLOC: {
			return ((mediumHeapEntry_s *)(((byte *)(p)) - ALIGN_SIZE( MEDIUM_HEADER_SIZE )))->size - ALIGN_SIZE( MEDIUM_HEADER_SIZE );
		}
		case LARGE_ALLOC: {
			return ((idHeap::page_s*)(*((dword *)(((byte *)p) - ALIGN_SIZE( LARGE_HEADER_SIZE )))))->dataSize - ALIGN_SIZE( LARGE_HEADER_SIZE );
		}
		default: {
			idLib::common->FatalError( "idHeap::Msize: invalid memory block (%s)", idLib::sys->GetCallStackCurStr( 4 ) );
			return 0;
		}
	}
#endif
}
开发者ID:sbrown345,项目名称:doom3_emscripten,代码行数:40,代码来源:Heap.cpp


示例3: init_alloc_root

void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
             size_t pre_alloc_size __attribute__((unused)))
{
  DBUG_ENTER("init_alloc_root");
  DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));

  mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
  mem_root->min_malloc= 32;
  mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
  mem_root->error_handler= 0;
  mem_root->block_num= 4;			/* We shift this with >>2 */
  mem_root->first_block_usage= 0;

#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
  if (pre_alloc_size)
  {
    if ((mem_root->free= mem_root->pre_alloc=
     (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
                   MYF(0))))
    {
      mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
      mem_root->free->left= pre_alloc_size;
      mem_root->free->next= 0;
    }
  }
#endif
  DBUG_VOID_RETURN;
}
开发者ID:16898500,项目名称:SkyFireEMU,代码行数:28,代码来源:my_alloc.c


示例4: init_alloc_root

void init_alloc_root(PSI_memory_key key,
                     MEM_ROOT *mem_root, size_t block_size,
		     size_t pre_alloc_size __attribute__((unused)))
{
  DBUG_ENTER("init_alloc_root");
  DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));

  mem_root->free= mem_root->used= mem_root->pre_alloc= 0;
  mem_root->min_malloc= 32;
  mem_root->block_size= block_size - ALLOC_ROOT_MIN_BLOCK_SIZE;
  mem_root->error_handler= 0;
  mem_root->block_num= 4;			/* We shift this with >>2 */
  mem_root->first_block_usage= 0;
  mem_root->m_psi_key= key;
  mem_root->max_capacity= 0;
  mem_root->allocated_size= 0;
  mem_root->error_for_capacity_exceeded= FALSE;

#if defined(PREALLOCATE_MEMORY_CHUNKS)
  if (pre_alloc_size)
  {
    if ((mem_root->free= mem_root->pre_alloc=
	 (USED_MEM*) my_malloc(key,
                               pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
			       MYF(0))))
    {
      mem_root->free->size= (uint)(pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)));
      mem_root->free->left= (uint)pre_alloc_size;
      mem_root->free->next= 0;
      mem_root->allocated_size+= pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM));
    }
  }
#endif
  DBUG_VOID_RETURN;
}
开发者ID:Longhui,项目名称:mysql-5.7.9-readcode,代码行数:35,代码来源:my_alloc.c


示例5: UnpackDevicePath

EFI_DEVICE_PATH *
UnpackDevicePath (
    IN EFI_DEVICE_PATH  *DevPath
    )
{
    EFI_DEVICE_PATH     *Src, *Dest, *NewPath;
    UINTN               Size;
    
    //
    // Walk device path and round sizes to valid boundries
    //    

    Src = DevPath;
    Size = 0;
    for (; ;) {
        Size += DevicePathNodeLength(Src);
        Size += ALIGN_SIZE(Size);

        if (IsDevicePathEnd(Src)) {
            break;
        }

        Src = NextDevicePathNode(Src);
    }


    //
    // Allocate space for the unpacked path
    //

    NewPath = AllocateZeroPool (Size);
    if (NewPath) {

        ASSERT (((UINTN)NewPath) % MIN_ALIGNMENT_SIZE == 0);

        //
        // Copy each node
        //

        Src = DevPath;
        Dest = NewPath;
        for (; ;) {
            Size = DevicePathNodeLength(Src);
            CopyMem (Dest, Src, Size);
            Size += ALIGN_SIZE(Size);
            SetDevicePathNodeLength (Dest, Size);
            Dest->Type |= EFI_DP_TYPE_UNPACKED;
            Dest = (EFI_DEVICE_PATH *) (((UINT8 *) Dest) + Size);

            if (IsDevicePathEnd(Src)) {
                break;
            }

            Src = NextDevicePathNode(Src);
        }
    }

    return NewPath;
}
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:59,代码来源:dpath.c


示例6: alloc_root

gptr alloc_root(MEM_ROOT *mem_root, size_t Size)
{
#if defined(HAVE_purify) && defined(EXTRA_DEBUG)
  reg1 USED_MEM *next;
  Size+=ALIGN_SIZE(sizeof(USED_MEM));

  if (!(next = (USED_MEM*) my_malloc(Size,MYF(MY_WME))))
  {
    if (mem_root->error_handler)
      (*mem_root->error_handler)();
    return((gptr) 0);				/* purecov: inspected */
  }
  next->next=mem_root->used;
  mem_root->used=next;
  return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)));
#else
  size_t get_size,max_left;
  gptr point;
  reg1 USED_MEM *next;
  reg2 USED_MEM **prev;

  Size= ALIGN_SIZE(Size);
  prev= &mem_root->free;
  max_left=0;
  for (next= *prev ; next && next->left < Size ; next= next->next)
  {
    if (next->left > max_left)
      max_left=next->left;
    prev= &next->next;
  }
  if (! next)
  {						/* Time to alloc new block */
    get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
    if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size)
      get_size=mem_root->block_size;		/* Normal alloc */

    if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
    {
      if (mem_root->error_handler)
	(*mem_root->error_handler)();
      return((gptr) 0);				/* purecov: inspected */
    }
    next->next= *prev;
    next->size= get_size;
    next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
    *prev=next;
  }
  point= (gptr) ((char*) next+ (next->size-next->left));
  if ((next->left-= Size) < mem_root->min_malloc)
  {						/* Full block */
    *prev=next->next;				/* Remove block from list */
    next->next=mem_root->used;
    mem_root->used=next;
  }
  return(point);
#endif
}
开发者ID:dparnell,项目名称:MariaDB,代码行数:57,代码来源:my_alloc.c


示例7: reset_root_defaults

void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
                         size_t pre_alloc_size __attribute__((unused)))
{
  DBUG_ASSERT(alloc_root_inited(mem_root));

  mem_root->block_size= (((block_size - ALLOC_ROOT_MIN_BLOCK_SIZE) & ~1) |
                         (mem_root->block_size & 1));
#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG))
  if (pre_alloc_size)
  {
    size_t size= pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM));
    if (!mem_root->pre_alloc || mem_root->pre_alloc->size != size)
    {
      USED_MEM *mem, **prev= &mem_root->free;
      /*
        Free unused blocks, so that consequent calls
        to reset_root_defaults won't eat away memory.
      */
      while (*prev)
      {
        mem= *prev;
        if (mem->size == size)
        {
          /* We found a suitable block, no need to do anything else */
          mem_root->pre_alloc= mem;
          return;
        }
        if (mem->left + ALIGN_SIZE(sizeof(USED_MEM)) == mem->size)
        {
          /* remove block from the list and free it */
          *prev= mem->next;
          my_free(mem);
        }
        else
          prev= &mem->next;
      }
      /* Allocate new prealloc block and add it to the end of free list */
      if ((mem= (USED_MEM *) my_malloc(size,
                                       MYF(MALLOC_FLAG(mem_root->
                                                       block_size)))))
      {
        mem->size= size; 
        mem->left= pre_alloc_size;
        mem->next= *prev;
        *prev= mem_root->pre_alloc= mem; 
      }
      else
      {
        mem_root->pre_alloc= 0;
      }
    }
  }
  else
#endif
    mem_root->pre_alloc= 0;
}
开发者ID:knielsen,项目名称:mariadb,代码行数:56,代码来源:my_alloc.c


示例8: alloc_root

gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
{
#if defined(HAVE_purify) && defined(EXTRA_DEBUG)
  reg1 USED_MEM *next;
  Size+=ALIGN_SIZE(sizeof(USED_MEM));

  if (!(next = (USED_MEM*) my_malloc(Size,MYF(MY_WME))))
  {
    if (mem_root->error_handler)
      (*mem_root->error_handler)();
    return((gptr) 0);				/* purecov: inspected */
  }
  next->next= mem_root->used;
  next->size= Size;
  mem_root->used= next;
  return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)));
#else
  uint get_size, block_size;
  gptr point;
  reg1 USED_MEM *next= 0;
  reg2 USED_MEM **prev;

  Size= ALIGN_SIZE(Size);
  if ((*(prev= &mem_root->free)) != NULL)
  {
    if ((*prev)->left < Size &&
	mem_root->first_block_usage++ >= ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP &&
	(*prev)->left < ALLOC_MAX_BLOCK_TO_DROP)
    {
      next= *prev;
      *prev= next->next;			/* Remove block from list */
      next->next= mem_root->used;
      mem_root->used= next;
      mem_root->first_block_usage= 0;
    }
    for (next= *prev ; next && next->left < Size ; next= next->next)
      prev= &next->next;
  }
  if (! next)
  {						/* Time to alloc new block */
    block_size= mem_root->block_size * (mem_root->block_num >> 2);
    get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
    get_size= max(get_size, block_size);

    if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
    {
      if (mem_root->error_handler)
	(*mem_root->error_handler)();
      return((gptr) 0);				/* purecov: inspected */
    }
    mem_root->block_num++;
    next->next= *prev;
    next->size= get_size;
    next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
    *prev=next;
  }
开发者ID:OPSF,项目名称:uClinux,代码行数:56,代码来源:my_alloc.c


示例9: rx_tcd_init

/* Initialize the Rx Transmit Control Discriptor parameters*/
static void rx_tcd_init(struct tdm_priv *priv)
{
	int i;
	u32 iter;
	u32 offset;
	dma_addr_t physaddr;
	int bytes_in_fifo_per_frame =
	    ALIGN_SIZE(priv->cfg.num_ch * priv->cfg.ch_width, 8);

	iter = bytes_in_fifo_per_frame / 8 * priv->cfg.num_frames;

	for (i = 0; i < NUM_OF_TDM_BUF; i++) {
		/* TDM RX fifo address */
		priv->dma_rx_tcd[i]->tcd[0] = TDM_RDR_OFFSET + priv->ptdm_base;

		/* ssize=dsize=64bit, soff=smod=dmod=0 */
		priv->dma_rx_tcd[i]->tcd[1] =
		    DMA_TCD1_SSIZE(SSIZE_64BITS) | DMA_TCD1_DSIZE(SSIZE_64BITS);

		/* number of bytes for minor loop, wide fifo 8bytes for dma */
		priv->dma_rx_tcd[i]->tcd[2] = 8;

		/* slast = 0 */
		priv->dma_rx_tcd[i]->tcd[3] = 0;

		offset = i * priv->cfg.num_frames * bytes_in_fifo_per_frame;

		/* dadr = rx buffer address */
		priv->dma_rx_tcd[i]->tcd[4] = priv->dma_input_paddr + offset;

		/* channel to channel linking is disabled ,
		 * destination offset is inc destination adr by 8,
		 * current iteration(citer) = number of transfers for frame
		 */
		priv->dma_rx_tcd[i]->tcd[5] =
		    DMA_TCD5_DOFF(0x08) | DMA_TCD5_CITER_DISABLE_LINK(iter);

		/* enable scater gather, interrupt on 1 Frame, */
		priv->dma_rx_tcd[i]->tcd[7] =
		    DMA_TCD7_BITER_DISABLE_LINK(iter) | DMA_TCD7_E_SG |
		    DMA_TCD7_INT_MAJ;
		priv->dma_rx_tcd[i]->tcd[6] = 0;
	}

	/* Next TCD for SG operation */
	physaddr = priv->dma_rx_tcd_paddr;
	priv->dma_rx_tcd[2]->tcd[6] =
	    ALIGN_SIZE(physaddr, ALIGNED_32_BYTES);
	physaddr += TCD_BUFFER_SIZE;
	priv->dma_rx_tcd[0]->tcd[6] =
	    ALIGN_SIZE(physaddr, ALIGNED_32_BYTES);
	physaddr += TCD_BUFFER_SIZE;
	priv->dma_rx_tcd[1]->tcd[6] =
	    ALIGN_SIZE(physaddr, ALIGNED_32_BYTES);
}
开发者ID:DavionKnight,项目名称:H18CE-1604C,代码行数:56,代码来源:tdm_fsl_starlite.c


示例10: sizeof

DataList::Head *DataList::Alloc(void *data, int data_size, int need_size)
{
	Head	*cur = NULL;
	int		alloc_size = need_size + sizeof(Head);

	alloc_size = ALIGN_SIZE(alloc_size, 8);

	if (!top) {
		cur = top = end = (Head *)buf.Buf();
		cur->next = cur->prior = NULL;
	}
	else {
		if (top >= end) {
			cur = (Head *)((BYTE *)top + top->alloc_size);
			if ((BYTE *)cur + alloc_size < buf.Buf() + buf.MaxSize()) {
				int need_grow = (int)(((BYTE *)cur + alloc_size) - (buf.Buf() + buf.Size()));
				if (need_grow > 0) {
					if (!buf.Grow(ALIGN_SIZE(need_grow, PAGE_SIZE))) {
						MessageBox(0, "can't alloc mem", "", MB_OK);
						goto END;
					}
				}
			}
			else {
				if ((BYTE *)end < buf.Buf() + alloc_size) {	// for debug
					MessageBox(0, "buf is too small", "", MB_OK);
					goto END;
				}
				cur = (Head *)buf.Buf();
			}
		}
		else {
			if ((BYTE *)end < (BYTE *)top + top->alloc_size + alloc_size) {	// for debug
				MessageBox(0, "buf is too small2", "", MB_OK);
				goto END;
			}
			cur = (Head *)((BYTE *)top + top->alloc_size);
		}
		top->next = cur;
		cur->prior = top;
		cur->next = NULL;
		top = cur;
	}
	cur->alloc_size = alloc_size;
	cur->data_size = data_size;
	if (data) {
		memcpy(cur->data, data, data_size);
	}
	buf.AddUsedSize(alloc_size);
	num++;

END:
	return	cur;
}
开发者ID:BrunoReX,项目名称:fastcopy,代码行数:54,代码来源:utility.cpp


示例11: my_dirend

void my_dirend(MY_DIR *buffer)
{
  DBUG_ENTER("my_dirend");
  if (buffer)
  {
    delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 
                                    ALIGN_SIZE(sizeof(MY_DIR))));
    free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 
                          ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
    my_free(buffer);
  }
  DBUG_VOID_RETURN;
} /* my_dirend */
开发者ID:Springlin,项目名称:david-mysql-tools,代码行数:13,代码来源:my_lib.c


示例12: free_root

void free_root(MEM_ROOT *root, myf MyFlags)
{
  reg1 USED_MEM *next,*old;
  DBUG_ENTER("free_root");

  if (!root)
    DBUG_VOID_RETURN; /* purecov: inspected */
  if (!(MyFlags & MY_KEEP_PREALLOC))
    root->pre_alloc=0;

  for ( next=root->used; next ;)
  {
    old=next; next= next->next ;
    if (old != root->pre_alloc)
      my_free((gptr) old,MYF(0));
  }
  for (next= root->free ; next ; )
  {
    old=next; next= next->next ;
    if (old != root->pre_alloc)
      my_free((gptr) old,MYF(0));
  }
  root->used=root->free=0;
  if (root->pre_alloc)
  {
    root->free=root->pre_alloc;
    root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
    root->free->next=0;
  }
  DBUG_VOID_RETURN;
}
开发者ID:dparnell,项目名称:MariaDB,代码行数:31,代码来源:my_alloc.c


示例13: check_ptr

static int check_ptr(const char *where, uchar *ptr, const char *filename,
		     uint lineno)
{
  if (!ptr)
  {
    fprintf(stderr, "Error: %s NULL pointer at line %d, '%s'\n",
	    where,lineno, filename);
    DBUG_PRINT("safe",("Null pointer at line %d '%s'", lineno, filename));
    (void) fflush(stderr);
    return 1;
  }
#ifndef _MSC_VER
  if ((long) ptr & (ALIGN_SIZE(1)-1))
  {
    fprintf(stderr, "Error: %s wrong aligned pointer at line %d, '%s'\n",
	    where,lineno, filename);
    DBUG_PRINT("safe",("Wrong aligned pointer at line %d, '%s'",
		       lineno,filename));
    (void) fflush(stderr);
    return 1;
  }
#endif
  if (ptr < sf_min_adress || ptr > sf_max_adress)
  {
    fprintf(stderr, "Error: %s pointer out of range at line %d, '%s'\n",
	    where,lineno, filename);
    DBUG_PRINT("safe",("Pointer out of range at line %d '%s'",
		       lineno,filename));
    (void) fflush(stderr);
    return 1;
  }
  return 0;
}
开发者ID:GRMrGecko,项目名称:MGMDB,代码行数:33,代码来源:safemalloc.c


示例14: bf_malloc

//No. 2 Best fit algorithm                                                                                                                                                           
void * bf_malloc(size_t size){
  t_block b,last;//,size_of_whole_block;
  size_t s; 
  s = ALIGN_SIZE(size, sizeof(char*));
  //size_of_used_block += size;
  if (base){
    //find the best block
    last = base;
    b = find_best_block (&last, s);
    //size_of_whole_block=last;
    if (b){
      // size_of_whole_block->size += b->size;
      //is it big enough to be split                                                                                                                                                 
      if ((b->size - s)>= (BLOCK_SIZE + 4 ))
        split_block (b,s);
      b->free = 0;//mark the chunk as used                                                                                                                                           
    } else {//otherwise we extend the heap(NO FITTING BLOCK )                                                                                                                        
      b = extend_heap(last,s);
      if (!b)
        return NULL;
    }
  }
  else {//Heap is empty (first time allocation)                                                                                                                                      
    b = extend_heap(NULL,s);
    if(!b)
      return(NULL);
    base = b;
  }
  //size_of_whole_block->size += b->size;
  head = b;
  return (b-> data);
}
开发者ID:Davodu,项目名称:my_malloc,代码行数:33,代码来源:my_malloc.c


示例15: rt2x00queue_payload_align

void rt2x00queue_payload_align(struct sk_buff *skb,
			       bool l2pad, unsigned int header_length)
{
	struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
	unsigned int frame_length = skb->len;
	unsigned int align = ALIGN_SIZE(skb, header_length);

	if (!align)
		return;

	if (l2pad) {
		if (skbdesc->flags & SKBDESC_L2_PADDED) {
			/* Remove L2 padding */
			memmove(skb->data + align, skb->data, header_length);
			skb_pull(skb, align);
			skbdesc->flags &= ~SKBDESC_L2_PADDED;
		} else {
			/* Add L2 padding */
			skb_push(skb, align);
			memmove(skb->data, skb->data + align, header_length);
			skbdesc->flags |= SKBDESC_L2_PADDED;
		}
	} else {
		/* Generic payload alignment to 4-byte boundary */
		skb_push(skb, align);
		memmove(skb->data, skb->data + align, frame_length);
	}
}
开发者ID:AppEngine,项目名称:linux-2.6,代码行数:28,代码来源:rt2x00queue.c


示例16: BCMATTACHFN

/*
 * bcm_mpm_get_obj_size() - The size of memory objects may need to be padded to
 *                          compensate for alignment requirements of the objects.
 *                          This function provides the padded object size. If clients
 *                          pre-allocate a memory slab for a memory pool, the
 *                          padded object size should be used by the client to allocate
 *                          the memory slab (in order to provide sufficent space for
 *                          the maximum number of objects).
 *
 * Parameters:
 *    mgr:            INPUT   The handle to the pools manager.
 *    obj_sz:         INPUT   Input object size.
 *    padded_obj_sz:  OUTPUT  Padded object size.
 *
 * Returns:
 *    BCME_OK      Ok
 *    BCME_BADARG  Bad arguments.
 *
 */
int BCMATTACHFN(bcm_mpm_get_obj_size)(bcm_mpm_mgr_h mgr, unsigned int obj_sz,
                                      unsigned int *padded_obj_sz)
{
	UNUSED_PARAMETER(mgr);

	/* Check parameters */
	if (obj_sz == 0) {
		return (BCME_BADARG);
	}


	/* A linked-list of free memory objects is maintained by the memory pool.
	 * While free, the contents of the memory object body itself is used for the
	 * linked-list pointers. (Therefore no per-memory-object meta-data is
	 * maintained).
	 *
	 * If the requested memory object size is less than the size of free-list
	 * pointer, pad the object size.
	 *
	 * Also, if the requested memory object size is not pointer aligned, pad
	 * the object size so that the "next" free-list pointers are aligned correctly.
	 */
	if (obj_sz < sizeof(bcm_mp_free_list_t)) {
		*padded_obj_sz = sizeof(bcm_mp_free_list_t);
	}
	else {
		*padded_obj_sz = ALIGN_SIZE(obj_sz, sizeof(void*));
	}

	return (BCME_OK);
}
开发者ID:Hosting-Scripts,项目名称:asuswrt-merlin,代码行数:50,代码来源:bcm_mpool.c


示例17: wf_malloc

void * wf_malloc (size_t size){
  t_block b, last;//, size_of_whole_block;
  size_t s;
  //aligning the requested size using the macro defined in my_malloc.h                                                                        
  s = ALIGN_SIZE(size, sizeof(char*));
  //if base is initialized, we can proceed to implement malloc                                                                                
  //size_of_used_block += size;
  if(base){
    //first find a block                                                                                                                      
    last = base;
    b = find_worst_block (&last,s);
    //size_of_whole_block=last;
    if (b){
      // size_of_whole_block->size += b->size;
      //is it big enough to be split                                                                                                          
      if((b->size - s)>= (BLOCK_SIZE + 4 ))
        split_block (b,s);
      b->free = 0;//mark the chunk as used                                                                                                    
    } else {//otherwise we extend the heap(NO FITTING BLOCK )                                                                                 
      b = extend_heap(last,s);
      if (!b)
        return NULL;
    }
  }
  else {//Heap is empty (first time allocation)                                                                                             
    b = extend_heap(NULL,s);
    if(!b)
      return(NULL);
    base = b;
  }
  //size_of_whole_block->size += b->size;
  head = b;
  return (b->data);
}
开发者ID:Davodu,项目名称:my_malloc,代码行数:34,代码来源:my_malloc.c


示例18: tdm_fsl_starlite_read

static u32 tdm_fsl_starlite_read(struct tdm_adapter *adap,
		u16 **input_tdm_buffer)
{
	struct tdm_priv *priv = tdm_get_adapdata(adap);
	u8 phase_rx;
	u32 buf_addr, buf_size;
	/* point to where to start for the current phase data processing */
	int bytes_in_fifo_per_frame =
	    ALIGN_SIZE(priv->cfg.num_ch * priv->cfg.ch_width, 8);

	if (priv->tdm_active == 0) {
		dev_warn(priv->device, "TDM is not ready");
		return 0;
	}

	if (priv->phase_rx == 0)
		phase_rx = NUM_OF_TDM_BUF - 1;
	else
		phase_rx = priv->phase_rx - 1;

	buf_size = bytes_in_fifo_per_frame * priv->cfg.num_frames;
	buf_addr = buf_size * phase_rx;
	*input_tdm_buffer = (u16 *)(priv->tdm_input_data + buf_addr);

	return buf_size;
}
开发者ID:DavionKnight,项目名称:H18CE-1604C,代码行数:26,代码来源:tdm_fsl_starlite.c


示例19: tdm_fsl_starlite_get_write_buf

static u32 tdm_fsl_starlite_get_write_buf(struct tdm_adapter *adap,
		u16 **output_tdm_buffer)
{
	struct tdm_priv *priv = tdm_get_adapdata(adap);
	u32 tmp;
	u8 phase_tx;
	u32 buf_addr, buf_size;
	/* point to where to start for the current phase data processing */
	int bytes_in_fifo_per_frame =
	    ALIGN_SIZE(priv->cfg.num_ch * priv->cfg.ch_width, 8);

	if (priv->tdm_active == 0) {
		dev_warn(priv->device, "TDM is not ready");
		return 0;
	}

	tmp = in_be32(&priv->dmac_regs->tcd[TDMTX_DMA_CH].tcd[0]);

	tmp -= priv->dma_tx_tcd[0]->tcd[0];

	priv->phase_tx = tmp / (bytes_in_fifo_per_frame * priv->cfg.num_frames);

	if (priv->phase_tx == 0)
		phase_tx = NUM_OF_TDM_BUF - 1;
	else
		phase_tx = priv->phase_tx - 1;

	buf_size = bytes_in_fifo_per_frame * priv->cfg.num_frames;
	buf_addr = buf_size * phase_tx;
	*output_tdm_buffer = (u16 *)(priv->tdm_output_data + buf_addr);

	return buf_size;
}
开发者ID:DavionKnight,项目名称:H18CE-1604C,代码行数:33,代码来源:tdm_fsl_starlite.c


示例20: DBUG_ENTER

void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
{
  struct st_irem *irem;
  uchar *data;
  DBUG_ENTER("_mymalloc");
  DBUG_PRINT("enter",("Size: %lu", (ulong) size));

  if (!sf_malloc_quick)
    (void) _sanity (filename, lineno);

  if (size + sf_malloc_cur_memory > sf_malloc_mem_limit)
    irem= 0;
  else
  {
    /* Allocate the physical memory */
    irem= (struct st_irem *) malloc (ALIGN_SIZE(sizeof(struct st_irem)) +
				     sf_malloc_prehunc +
				     size +	/* size requested */
				     4 +	/* overrun mark */
				     sf_malloc_endhunc);
    DBUG_EXECUTE_IF("simulate_out_of_memory",
                    {
                      free(irem);
                      irem= NULL;
                    });
开发者ID:ystk,项目名称:debian-mysql-5.1,代码行数:25,代码来源:safemalloc.c



注:本文中的ALIGN_SIZE函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ALLEGRO_DEBUG函数代码示例发布时间:2022-05-30
下一篇:
C++ ALIGN_DOWN函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap