当前位置: 首页>>代码示例>>C++>>正文


C++ MEM_ALIGN函数代码示例

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


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

示例1: t_pop_verify

static void t_pop_verify(void)
{
	struct stack_block *block;
	unsigned char *p;
	size_t pos, max_pos, used_size, alloc_size;

	block = current_frame_block->block[frame_pos];
	pos = block->size - current_frame_block->block_space_used[frame_pos];
	while (block != NULL) {
		used_size = block->size - block->left;
		p = STACK_BLOCK_DATA(block);
		while (pos < used_size) {
			alloc_size = *(size_t *)(p + pos);
			if (used_size - pos < alloc_size)
				i_panic("data stack: saved alloc size broken");
			pos += MEM_ALIGN(sizeof(alloc_size));
			max_pos = pos + MEM_ALIGN(alloc_size + SENTRY_COUNT);
			pos += alloc_size;

			for (; pos < max_pos; pos++) {
				if (p[pos] != CLEAR_CHR)
					i_panic("data stack: buffer overflow");
			}
		}

		/* if we had used t_buffer_get(), the rest of the buffer
		   may not contain CLEAR_CHRs. but we've already checked all
		   the allocations, so there's no need to check them anyway. */
		block = block->next;
		pos = 0;
	}
}
开发者ID:Distrotech,项目名称:dovecot,代码行数:32,代码来源:data-stack.c

示例2: pbuf_init

/**
 * Initializes the pbuf module.
 *
 * A large part of memory is allocated for holding the pool of pbufs.
 * The size of the individual pbufs in the pool is given by the size
 * parameter, and the number of pbufs in the pool by the num parameter.
 *
 * After the memory has been allocated, the pbufs are set up. The
 * ->next pointer in each pbuf is set up to point to the next pbuf in
 * the pool.
 *
 */
void
pbuf_init(void)
{
  struct pbuf *p, *q = NULL;
  u16_t i;

  pbuf_pool = (struct pbuf *)MEM_ALIGN(pbuf_pool_memory);

#if PBUF_STATS
  lwip_stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */

  /* Set up ->next pointers to link the pbufs of the pool together */
  p = pbuf_pool;

  for(i = 0; i < PBUF_POOL_SIZE; ++i) {
    p->next = (struct pbuf *)((u8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
    p->len = p->tot_len = PBUF_POOL_BUFSIZE;
    p->payload = MEM_ALIGN((void *)((u8_t *)p + sizeof(struct pbuf)));
    p->flags = PBUF_FLAG_POOL;
    q = p;
    p = p->next;
  }

  /* The ->next pointer of last pbuf is NULL to indicate that there
     are no more pbufs in the pool */
  q->next = NULL;

#if !SYS_LIGHTWEIGHT_PROT
  pbuf_pool_alloc_lock = 0;
  pbuf_pool_free_lock = 0;
  pbuf_pool_free_sem = sys_sem_new(1);
#endif
}
开发者ID:AldenHiggins,项目名称:ELEC424-Lab06-Scheduling-with-FreeRTOS,代码行数:46,代码来源:pbuf.c

示例3: memp_malloc

/*-----------------------------------------------------------------------------------*/
void *
memp_malloc(memp_t type)
{
    struct memp *memp;

    ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);

    memp = memp_tab[type];

    if(memp != NULL)
    {
        memp_tab[type] = memp->next;
        memp->next = NULL;
#ifdef MEMP_STATS
        ++stats.memp[type].used;
        if(stats.memp[type].used > stats.memp[type].max) {
            stats.memp[type].max = stats.memp[type].used;
        }
#endif /* MEMP_STATS */
        ASSERT("memp_malloc: memp properly aligned",
                ((uint32_t)MEM_ALIGN((uint8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);

        return MEM_ALIGN((uint8_t *)memp + sizeof(struct memp));
    } else {
        DEBUGF(MEMP_DEBUG, ("memp_malloc: out of memory in pool %d\n", type));
#ifdef MEMP_STATS
        ++stats.memp[type].err;
#endif /* MEMP_STATS */
        return NULL;
    }
}
开发者ID:1573472562,项目名称:netfpga,代码行数:32,代码来源:memp.c

示例4: malloc

void* malloc(u32 size)
{
    mem_block_t* block = pool.current;
    while (block != NULL)
    {
        u8* mem = MEM_ALIGN(block->current, ALIGN_SIZE);
        if ((u32)(block->end - mem) >= size)
            break;

        block = pool.current->next;
    }

    if (block == NULL)
    {
        block = alloc_block(size);
        pool.last->next = block;
        pool.last = block;
    }

    u8* mem = MEM_ALIGN(block->current, ALIGN_SIZE);
    if ((u32)(block->end - mem) >= size)
    {
        block->current += size;
        return mem;
    }

    return NULL;
}
开发者ID:guzhoudiaoke,项目名称:babyos,代码行数:28,代码来源:malloc.c

示例5: data_stack_last_buffer_reset

static void data_stack_last_buffer_reset(bool preserve_data ATTR_UNUSED)
{
	if (last_buffer_block != NULL) {
#ifdef DEBUG
		unsigned char *p;
		unsigned int i;

		p = STACK_BLOCK_DATA(current_block) +
			(current_block->size - current_block->left) +
			MEM_ALIGN(sizeof(size_t)) + MEM_ALIGN(last_buffer_size);
#endif
		/* reset t_buffer_get() mark - not really needed but makes it
		   easier to notice if t_malloc()/t_push()/t_pop() is called
		   between t_buffer_get() and t_buffer_alloc().
		   do this before we get to i_panic() to avoid recursive
		   panics. */
		last_buffer_block = NULL;

#ifdef DEBUG
		for (i = 0; i < SENTRY_COUNT; i++) {
			if (p[i] != CLEAR_CHR)
				i_panic("t_buffer_get(): buffer overflow");
		}

		if (!preserve_data) {
			p = STACK_BLOCK_DATA(current_block) +
				(current_block->size - current_block->left);
			memset(p, CLEAR_CHR, SENTRY_COUNT);
		}
#endif
	}
}
开发者ID:Distrotech,项目名称:dovecot,代码行数:32,代码来源:data-stack.c

示例6: HeapUnpopStack

/* allocate some space on the stack, in the current stack frame */
void HeapUnpopStack(int Size)
{
#ifdef DEBUG_HEAP
    printf("HeapUnpopStack(%ld) at 0x%lx\n", (unsigned long)MEM_ALIGN(Size), (unsigned long)HeapStackTop);
#endif
    HeapStackTop = (void *)((char *)HeapStackTop + MEM_ALIGN(Size));
}
开发者ID:AtomSoftTech,项目名称:retrobsd,代码行数:8,代码来源:heap.c

示例7: VariableAlloc

/* allocate a value either on the heap or the stack using space dependent on what type we want */
struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap)
{
    struct Value *NewValue = VariableAlloc(Parser, MEM_ALIGN(sizeof(struct Value)) + DataSize, OnHeap);
    NewValue->Val = (union AnyValue *)((char *)NewValue + MEM_ALIGN(sizeof(struct Value)));
    NewValue->ValOnHeap = OnHeap;
    NewValue->ValOnStack = !OnHeap;
    NewValue->IsLValue = IsLValue;
    NewValue->LValueFrom = LValueFrom;
    return NewValue;
}
开发者ID:fjrti,项目名称:remix,代码行数:11,代码来源:variable.c

示例8: memp_malloc

void *
memp_malloc(memp_t type)
{
  struct memp *memp;
  void *mem;
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_DECL_PROTECT(old_level);
#endif
 
  LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);

#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */  
  sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */  

  memp = memp_tab[type];
  
  if (memp != NULL) {    
    memp_tab[type] = memp->next;    
    memp->next = NULL;
#if MEMP_STATS
    ++lwip_stats.memp[type].used;
    if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
      lwip_stats.memp[type].max = lwip_stats.memp[type].used;
    }
#endif /* MEMP_STATS */
#if SYS_LIGHTWEIGHT_PROT
    SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
    sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */  
    LWIP_ASSERT("memp_malloc: memp properly aligned",
     ((mem_ptr_t)MEM_ALIGN((u8_t *)memp + sizeof(struct memp)) % MEM_ALIGNMENT) == 0);

    mem = MEM_ALIGN((u8_t *)memp + sizeof(struct memp));
    return mem;
  } else {
    LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %d\n", type));
#if MEMP_STATS
    ++lwip_stats.memp[type].err;
#endif /* MEMP_STATS */
#if SYS_LIGHTWEIGHT_PROT
  SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */
  sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */  
    return NULL;
  }
}
开发者ID:3a1fa340-312c-11e6-8775-0016d322cfd3,项目名称:4b204d7c-312f-11e6-bd79-0016d322cfd3,代码行数:51,代码来源:memp.c

示例9: lm32_block_move_inline

static void
lm32_block_move_inline (rtx dest, rtx src, HOST_WIDE_INT length, HOST_WIDE_INT alignment)
{
    HOST_WIDE_INT offset, delta;
    unsigned HOST_WIDE_INT bits;
    int i;
    enum machine_mode mode;
    rtx *regs;

    /* Work out how many bits to move at a time.  */
    switch (alignment)
    {
    case 1:
        bits = 8;
        break;
    case 2:
        bits = 16;
        break;
    case 4:
        bits = 32;
        break;
    default:
        abort ();
    }

    mode = mode_for_size (bits, MODE_INT, 0);
    delta = bits / BITS_PER_UNIT;

    /* Allocate a buffer for the temporary registers.  */
    regs = alloca (sizeof (rtx) * length / delta);

    /* Load as many BITS-sized chunks as possible.  */
    for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
    {
        regs[i] = gen_reg_rtx (mode);
        emit_move_insn (regs[i], adjust_address (src, mode, offset));
    }

    /* Copy the chunks to the destination.  */
    for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
        emit_move_insn (adjust_address (dest, mode, offset), regs[i]);

    /* Mop up any left-over bytes.  */
    if (offset < length)
    {
        src = adjust_address (src, BLKmode, offset);
        dest = adjust_address (dest, BLKmode, offset);
        move_by_pieces (dest, src, length - offset,
                        MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
    }
}
开发者ID:FullMentalPanic,项目名称:RTEMS_NEW_TOOL_CHAIN,代码行数:51,代码来源:lm32.c

示例10: MEM_ALIGN

/* allocate some space on the stack, in the current stack frame
 * clears memory. can return NULL if out of stack space */
void *HeapAllocStack(int Size)
{
    char *NewMem = HeapStackTop;
    char *NewTop = (char *)HeapStackTop + MEM_ALIGN(Size);
#ifdef DEBUG_HEAP
    printf("HeapAllocStack(%ld) at 0x%lx\n", (unsigned long)MEM_ALIGN(Size), (unsigned long)HeapStackTop);
#endif
    if (NewTop > (char *)HeapBottom)
        return NULL;
        
    HeapStackTop = (void *)NewTop;
    memset((void *)NewMem, '\0', Size);
    return NewMem;
}
开发者ID:AtomSoftTech,项目名称:retrobsd,代码行数:16,代码来源:heap.c

示例11: pbuf_init

/*-----------------------------------------------------------------------------------*/
void
pbuf_init(void)
{
  struct pbuf *p, *q;
  uint8_t i;

  pbuf_pool = (struct pbuf *)&pbuf_pool_memory[0];
  ASSERT("pbuf_init: pool aligned", (long)pbuf_pool % MEM_ALIGNMENT == 0);

#ifdef PBUF_STATS
  stats.pbuf.avail = PBUF_POOL_SIZE;
#endif /* PBUF_STATS */

  /* Set up ->next pointers to link the pbufs of the pool together. */
  p = pbuf_pool;

  for(i = 0; i < PBUF_POOL_SIZE; ++i) {
    p->next = (struct pbuf *)((uint8_t *)p + PBUF_POOL_BUFSIZE + sizeof(struct pbuf));
    p->len = p->tot_len = PBUF_POOL_BUFSIZE;
    p->payload = MEM_ALIGN((void *)((uint8_t *)p + sizeof(struct pbuf)));
    q = p;
    p = p->next;
  }

  /* The ->next pointer of last pbuf is NULL to indicate that there
     are no more pbufs in the pool. */
  q->next = NULL;

  pbuf_pool_alloc_lock = 0;
  pbuf_pool_free_lock = 0;
  pbuf_pool_free_sem = sys_sem_new(1);

}
开发者ID:1573472562,项目名称:netfpga,代码行数:34,代码来源:pbuf.c

示例12: StdioBaseScanf

/* internal do-anything v[s][n]scanf() formatting system with input from strings or FILE * */
int StdioBaseScanf(struct ParseState *Parser, FILE *Stream, char *StrIn, char *Format, struct StdVararg *Args)
{
    struct Value *ThisArg = Args->Param[0];
    int ArgCount = 0;
    void *ScanfArg[MAX_SCANF_ARGS];
    
    if (Args->NumArgs > MAX_SCANF_ARGS)
        ProgramFail(Parser, "too many arguments to scanf() - %d max", MAX_SCANF_ARGS);
    
    for (ArgCount = 0; ArgCount < Args->NumArgs; ArgCount++)
    {
        ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
        
        if (ThisArg->Typ->Base == TypePointer) 
            ScanfArg[ArgCount] = ThisArg->Val->Pointer;
        
        else if (ThisArg->Typ->Base == TypeArray)
            ScanfArg[ArgCount] = &ThisArg->Val->ArrayMem[0];
        
        else
            ProgramFail(Parser, "non-pointer argument to scanf() - argument %d after format", ArgCount+1);
    }
    
    if (Stream != NULL)
        return fscanf(Stream, Format, ScanfArg[0], ScanfArg[1], ScanfArg[2], ScanfArg[3], ScanfArg[4], ScanfArg[5], ScanfArg[6], ScanfArg[7], ScanfArg[8], ScanfArg[9]);
    else
        return sscanf(StrIn, Format, ScanfArg[0], ScanfArg[1], ScanfArg[2], ScanfArg[3], ScanfArg[4], ScanfArg[5], ScanfArg[6], ScanfArg[7], ScanfArg[8], ScanfArg[9]);
}
开发者ID:galacticstudios,项目名称:picoc,代码行数:29,代码来源:stdio.c

示例13: t_try_realloc

bool t_try_realloc(void *mem, size_t size)
{
	size_t last_alloc_size;

	if (unlikely(size == 0 || size > SSIZE_T_MAX))
		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);

	last_alloc_size = current_frame_block->last_alloc_size[frame_pos];

	/* see if we're trying to grow the memory we allocated last */
	if (STACK_BLOCK_DATA(current_block) +
	    (current_block->size - current_block->left -
	     last_alloc_size) == mem) {
		/* yeah, see if we have space to grow */
		size = MEM_ALIGN(size);
		if (current_block->left >= size - last_alloc_size) {
			/* just shrink the available size */
			current_block->left -= size - last_alloc_size;
			current_frame_block->last_alloc_size[frame_pos] = size;
			return TRUE;
		}
	}

	return FALSE;
}
开发者ID:Distrotech,项目名称:dovecot,代码行数:25,代码来源:data-stack.c

示例14: mem_dump

void mem_dump(mem_pool_t *m){
    mheader_t *h;

    //mutex_lock (&m->lock);
    debug_printf ("\npool $%x:", m);
    mheader_t* limit = (mheader_t*)((size_t)m->store+m->size);
    for (h=(mheader_t*)m->store; h<limit; h=SUCC(h)) {
        if (h->pool != m){
            debug_printf ("bad block $%x[$%x]:$%hx on pool[$%x]\n"
                    , h, h->size
                    , h->magic, h->pool);
            break;
        }

        if (h->magic == MEMORY_BLOCK_MAGIC)
            debug_printf ("$%x[$%x] ", h, h->size);
        else if (h->magic == MEMORY_HOLE_MAGIC)
            debug_printf ("$%x[$%x]:->$%x\n", h, h->size, NEXT(h));
        else {
            debug_printf ("$%x[$%x]:bad magic %2s=$%hx\n", h, h->size, &h->magic, (int)(h->magic));
            break;
        }
        if ( (h->size != MEM_ALIGN(h->size))
             || (h->size < (MEM_HSIZE+ SIZEOF_ALIGN))
             || ( h->size > ((size_t)limit - (size_t)h) )
           )
        {
            debug_printf ("bad block $%x size $%x\n", h, h->size);
            break;
        }
    }
    //mutex_unlock (&m->lock);
}
开发者ID:alexrayne,项目名称:uos-embedded,代码行数:33,代码来源:mem.c

示例15: mem_validate

void mem_validate(mem_pool_t *m){
    mheader_t *h;
    //mutex_lock (&m->lock);
    mheader_t* limit = (mheader_t*)((size_t)m->store+m->size);
    for (h=(mheader_t*)m->store; h<limit; h=SUCC(h)) {
        assert2( (h->pool == m)
                , "bad block $%x[$%x]:$%hx on pool[$%x]\n"
                , h, h->size
                , h->magic, h->pool
        );

        assert2( (h->magic == MEMORY_BLOCK_MAGIC) || (h->magic == MEMORY_HOLE_MAGIC)
                , "$%x[$%x]:bad magic %2s=$%hx\n"
                , h, h->size, &h->magic, (int)(h->magic)
                );
        assert2( ( (h->size == MEM_ALIGN(h->size))
                && (h->size >= (MEM_HSIZE+ SIZEOF_ALIGN))
                && (h->size <= ((size_t)limit - (size_t)h) )
                  )
                , "bad block $%x size $%x\n"
                , h, h->size
                );
    }
    //mutex_unlock (&m->lock);
}
开发者ID:alexrayne,项目名称:uos-embedded,代码行数:25,代码来源:mem.c


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