int main(void)
{
	void * p = malloc(103);
	void * q = malloc(1000);
	void * r = malloc(7);

	void * x = aligned_malloc(8, 100);
	void * y = aligned_malloc(32, 1035);
	void * z = aligned_malloc(4, 8);

	printf("Raw malloc pointers, no alignment enforced:\n");
	printf("\t%p, %p, %p\n", p, q, r);
	printf("\tNote: you may see 4-8 byte alignment on host PC\n");
	printf("aligned to 8: %p\n", x);
	printf("aligned to 32: %p\n", y);
	printf("aligned to 4: %p\n", z);

	aligned_free(x), x = NULL;
	aligned_free(y), y = NULL;
	aligned_free(z), z = NULL;

	free(p), p = NULL;
	free(q), q = NULL;
	free(r), r = NULL;

	return 0;
}
Example #2
0
int main(int argc, char **argv) {
    char **endptr;
    int alignment = atoi(argv[1]);
    int *p = (int *)aligned_malloc(100, alignment);
    int *q = (int *)aligned_malloc(128, alignment);
    int *r = (int *)aligned_malloc(128, alignment);
    
    printf("%s: %p\n", argv[1], p);
    aligned_free(p);
    aligned_free(q);
    aligned_free(r);
    return 0;
}
Example #3
0
void TimgFilterAwarpsharp::done(void)
{
    if (aws.work.yplane.ptr) {
        aligned_free(aws.work.yplane.ptr);
        aws.work.yplane.ptr = NULL;
    }
}
Example #4
0
 void OldPool::Compress()
 {
     auto mask = (size_t)-pageBufLen;
     auto numItemsPerPage = pageBufLen / itemBufLen;
     Dict<size_t, int> dict;
     for( int i = 0; i < items.Size(); ++i )
     {
         dict[ (size_t)items[ i ] & mask ] += 1;
     }
     for( int i = 0; i < items.Size(); ++i )
     {
         if( dict[ (size_t)items[ i ] & mask ] == numItemsPerPage )
         {
             items.EraseFast( i-- );
         }
     }
     for( int i = 0; i < pages.Size(); ++i )
     {
         if( dict[ (size_t)pages[ i ] ] == numItemsPerPage )
         {
             aligned_free( pages[ i ] );
             pages.EraseFast( i-- );
         }
     }
 }
Example #5
0
void OldPool::compress()
{
    auto mask = (size_t)-_pageBufLen;
    auto numItemsPerPage = _pageBufLen / _itemBufLen;
    Dict<size_t, int> dict;
    for( int i = 0; i < _items.size(); ++i )
    {
        dict[ (size_t)_items[ i ] & mask ] += 1;
    }
    for( int i = 0; i < _items.size(); ++i )
    {
        if( dict[ (size_t)_items[ i ] & mask ] == numItemsPerPage )
        {
            _items.eraseFast( i-- );
        }
    }
    for( int i = 0; i < _pages.size(); ++i )
    {
        if( dict[ (size_t)_pages[ i ] ] == numItemsPerPage )
        {
            aligned_free( _pages[ i ] );
            _pages.eraseFast( i-- );
        }
    }
}
Example #6
0
bool HapMap::loadHapBinary(const char* filename)
{
    aligned_free(m_data);
    
    std::ifstream f(filename, std::ios::in | std::ios::binary);
    if (!f.good())
    {
        std::cerr << "ERROR: Cannot open file or file not found: " << filename << std::endl;
        return false;
    }
    
    uint64_t check;
    f.read((char*) &check, sizeof(uint64_t));
    if (check != magicNumber)
    {
        std::cerr << "ERROR: Wrong file type: " << filename << ". Expected binary format." << std::endl;
        return false;
    }
    
    f.read((char*) &m_numSnps, sizeof(uint64_t));
    f.read((char*) &m_snpLength, sizeof(uint64_t));
    
    m_snpDataSize = ::bitsetSize<PrimitiveType>(m_snpLength);
    m_snpDataSize64 = ::bitsetSize<uint64_t>(m_snpLength);
    m_snpDataSizeULL = ::bitsetSize<unsigned long long>(m_snpLength);
    m_data = (PrimitiveType*) aligned_alloc(128, m_snpDataSize*m_numSnps*sizeof(PrimitiveType));
    
    for(uint64_t i = 0; i < m_numSnps; ++i)
        f.read((char*) &m_data[i*this->m_snpDataSize], sizeof(uint64_t)*m_snpDataSize64);
    
    return true;
}
Example #7
0
void merge(int num_threads, int length, pivot_data *before_merge, int* merged){
	//printf("In merge num_threads %d\n", num_threads);
	int i;
	for(i=0; i<num_threads; i++){
		before_merge[i].ctr=0;
		//printf("i %d length %d\n", i, before_merge[i].length);
	}
	//printf("length %d\n", length);
	int ctr = 0;
	pivot_data* dq;

	PQueue *pq =  pqueue_new(heap_compare_pivots, num_threads);

	for(i=0; i<num_threads; i++){
		pqueue_enqueue(pq, &before_merge[i]);
		//printf("Enqueue %d\n", before_merge[i].pivots[0]);
	}

	while(pq->size != 0){
		dq = (pivot_data*)pqueue_dequeue(pq);
		//printf("Dequeue %d\n", dq->pivots[dq->ctr]);
		merged[ctr++] = dq->pivots[dq->ctr++];
		if(dq->ctr != dq->length){
			pqueue_enqueue(pq, dq);
			//printf("Enqueue %d\n", dq->pivots[dq->ctr]);
		}
	}
	pqueue_delete(pq);

	aligned_free(before_merge);
}
Example #8
0
/**
 * Delete the given memory pool.
 */
void pool_delete(Pool_desc *mp)
{
	if (NULL == mp) return;
	lgdebug(+D_MEMPOOL, "Used %zu elements (pool '%s' created in %s())\n",
	        mp->curr_elements, mp->name, mp->func);

	/* Free its chained memory blocks. */
	char *c_next;
	size_t alloc_size;
#if POOL_ALLOCATOR
	alloc_size = mp->data_size;
#else
	alloc_size = mp->element_size;
#endif
	for (char *c = mp->chain; c != NULL; c = c_next)
	{
		c_next = POOL_NEXT_BLOCK(c, alloc_size);
#if POOL_ALLOCATOR
		aligned_free(c);
#else
		free(c);
#endif
	}
	free(mp);
}
void TimgFilterNoiseMplayer::Tprocess::done(void)
{
    if (noise) {
        aligned_free(noise);
    }
    noise=NULL;
    nonTempRandShift[0]=-1;
}
void TimgFilterNoise::doneChroma(void)
{
    for (int i=1; i<3; i++)
        if (noiseMask[i]) {
            aligned_free(noiseMask[i]);
            noiseMask[i]=NULL;
        }
}
void TimgFilterNoise::done(void)
{
    if (noiseMask[0]) {
        aligned_free(noiseMask[0]);
    }
    noiseMask[0]=NULL;
    doneChroma();
}
Example #12
0
int pnt_init()
{ aligned_free((void *)pnt); 
  pnt = 0;
  pnt = (pawn_entry_t *)aligned_malloc((size_t)PNTSIZE*sizeof(pawn_entry_t), PT_ALIGNMENT);
  if(!pnt) return false;
  aligned_wipe_out((void *)pnt, (size_t)PNTSIZE*sizeof(pawn_entry_t), PT_ALIGNMENT);
  return true;
}
 void uinit()
 {
   for(uint8_t i=0; i<depth; i++)                               // free buffers
   {
     aligned_free(buffers[i]);
   }
   free(tags);
   free(buffers);
 }
Example #14
0
int rest_destroy()
{
	pattern.clear();

	if (hash != NULL)
		aligned_free(hash);

	return 0;
}
/* __ompc_destroy_task_pool_simple:
 */
void __ompc_destroy_task_pool_simple(omp_task_pool_t *pool)
{
  int i;
  omp_task_queue_level_t *per_thread;

  Is_True(pool != NULL, ("__ompc_destroy_task_pool; pool is NULL"));

  per_thread = &pool->level[PER_THREAD];

  for (i = 0; i < pool->team_size; i++) {
    __ompc_queue_free_slots(&per_thread->task_queue[i]);
  }

  pthread_mutex_destroy(&pool->pool_lock);

  aligned_free(per_thread->task_queue); /* free queues in level 0 */
  aligned_free(pool->level); /* free the level array */
  aligned_free(pool); /* free the pool itself */
}
Example #16
0
void TimgFilterBlur::done(void)
{
    if (bluredPict) {
        aligned_free(bluredPict);
        bluredPict = NULL;
    }
    if (blur) {
        delete blur;
        blur = NULL;
    }
}
Example #17
0
File: gradfun.c Project: IAPark/vlc
static void Close(vlc_object_t *object)
{
    filter_t     *filter = (filter_t *)object;
    filter_sys_t *sys = filter->p_sys;

    var_DelCallback(filter, CFG_PREFIX "radius",   Callback, NULL);
    var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
    aligned_free(sys->cfg.buf);
    vlc_mutex_destroy(&sys->lock);
    free(sys);
}
Example #18
0
void TimgFilterWarpsharp::done(void)
{
    if (blur) {
        aligned_free(blur);
        blur = NULL;
    }
    if (swsblur) {
        libavcodec->sws_freeContext(swsblur);
    }
    swsblur = NULL;
}
Example #19
0
int main(int argc, const char **argv) {

    while(true) {
        switch (rpc_call) {
        case Message::None:
            break;
        case Message::Alloc:
            set_rpc_return(reinterpret_cast<int>(aligned_malloc(hvx_alignment, RPC_ARG(0))));
            break;
        case Message::Free:
            aligned_free(reinterpret_cast<void*>(RPC_ARG(0)));
            set_rpc_return(0);
            break;
        case Message::InitKernels:
            set_rpc_return(initialize_kernels(
                reinterpret_cast<unsigned char*>(RPC_ARG(0)),
                RPC_ARG(1),
                RPC_ARG(2),
                reinterpret_cast<handle_t*>(RPC_ARG(3))));
            break;
        case Message::GetSymbol:
            set_rpc_return(get_symbol(
                static_cast<handle_t>(RPC_ARG(0)),
                reinterpret_cast<const char *>(RPC_ARG(1)),
                RPC_ARG(2),
                RPC_ARG(3)));
            break;
        case Message::Run:
            set_rpc_return(run(
                static_cast<handle_t>(RPC_ARG(0)),
                static_cast<handle_t>(RPC_ARG(1)),
                reinterpret_cast<const buffer*>(RPC_ARG(2)),
                RPC_ARG(3),
                reinterpret_cast<buffer*>(RPC_ARG(4)),
                RPC_ARG(5),
                reinterpret_cast<const buffer*>(RPC_ARG(6)),
                RPC_ARG(7)));
            break;
        case Message::ReleaseKernels:
            set_rpc_return(release_kernels(
                static_cast<handle_t>(RPC_ARG(0)),
                RPC_ARG(1)));
            break;
        case Message::Break:
            return 0;
        default:
            log_printf("Unknown message: %d\n", rpc_call);
            return -1;
        }
    }
    log_printf("Unreachable!\n");
    return 0;
}
Example #20
0
static void
EvasImageBuffersFree( vout_display_t *vd )
{
    vout_display_sys_t *sys = vd->sys;

    for( unsigned int i = 0; i < sys->i_nb_buffers; i++ )
        aligned_free( sys->p_buffers[i].p[0] );
    free( sys->p_buffers );
    sys->p_buffers = NULL;
    sys->i_nb_buffers = 0;
    sys->i_nb_planes = 0;
}
Example #21
0
main()
{
	/* malloc adds a header before the pointer it returns to use in free
	   This header must not be modified and the original pointer must be
	   retrievable. So let's take a cue from malloc's book and add a
	   header of our own. This header is only 1 sizeof(void*) long and will
	   store the original address for use in aligned_free. It will be
	   located 1 sizeof(void*) before the pointer we return. This should
	   operate correctly regardless of the width of the memory address. */
	test = aligned_malloc(malloc_size, malloc_alignment);
	aligned_free(test);
}
Example #22
0
int main(void)
{
	void *p = malloc(1 + 127);
	char *pp = (char*)(((uintptr_t)p + 127) & (~(uintptr_t)127));
	printf("p : 0x%Lx \n", (long long unsigned int)p);
	printf("pp : 0x%Lx \n", (long long unsigned int)pp);
	printf("&p : 0x%Lx \n", (long long unsigned int)&p);
	printf("&pp : 0x%Lx \n", (long long unsigned int)&pp);
	free(p);	
	char *ptr = (char *)aligned_malloc(1, 128);
	printf("ptr : 0x%Lx \n", (long long unsigned int)ptr);
	aligned_free(ptr);
	return 0;
}
Example #23
0
void TimgFilterTomsMoComp::done(void)
{
    for (int i = 0; i < 3; i++) {
        if (psrc[i]) {
            aligned_free(psrc[i]);
        }
        psrc[i] = NULL;
    }
    if (t) {
        t->destroy();
    }
    t = NULL;
    inited = false;
}
 inline aligned_stack_buffer<T, A>::~aligned_stack_buffer()
 {
     if (!std::is_trivially_destructible<T>::value && m_ptr != 0)
     {
         for (auto p = m_ptr; p < m_ptr + m_size; ++p)
         {
             p->~T();
         }
     }
     if (m_heap_allocation)
     {
         aligned_free(m_ptr);
     }
 }
Example #25
0
void simple_soft_destroy(struct simple_soft_ctx *ctx)
{
	if(!ctx) return;

	if(ctx->map_surf[0]) aligned_free(ctx->map_surf[0]);
	if(ctx->map_surf[1]) aligned_free(ctx->map_surf[1]);
	if(ctx->fft_tmp) aligned_free(ctx->fft_tmp);
	if(ctx->cur_buf) aligned_free(ctx->cur_buf);
	if(ctx->prev_buf) aligned_free(ctx->prev_buf);

	if(ctx->maxsrc) maxsrc_delete(ctx->maxsrc);
	if(ctx->pal_ctx) pal_ctx_delete(ctx->pal_ctx);
	if(ctx->pd) destroy_point_data(ctx->pd);
	if(ctx->beat) beat_delete(ctx->beat);

	ctx->map_surf[0] = ctx->map_surf[1] = NULL;
	ctx->maxsrc = NULL;
	ctx->pal_ctx = NULL;
	ctx->pd = NULL;
	ctx->beat = NULL;
	ctx->cur_buf = ctx->prev_buf = ctx->fft_tmp = NULL;
	free(ctx);
}
int main() {
	size_t aligment = 256;

	printf("My aligned_malloc result:\n");
	int* p = (int*) aligned_malloc(256, aligment);
	aligned_free(p);

	printf("\nC11 aligned_malloc retult:\n");
	int *p1 =(int*) malloc(10*sizeof *p1);
    printf("default-aligned addr:\t%p\n", (void*)p1);
    free(p1);
 	
    int *p2 =(int*) aligned_alloc(aligment, 10*sizeof *p2);
    printf("%u-byte aligned addr: \t%p\n",aligment,(void*)p2);
    free(p2);
}
Example #27
0
bool HapMap::loadHapAscii(const char* filename, std::size_t maxLength)
{
    aligned_free(m_data);
    
    std::ifstream file(filename);
    if (!file.good())
    {
        std::cout << "ERROR: Cannot open file or file not found: " << filename << std::endl;
        return false;
    }
    m_numSnps = 1ULL;
    std::string line;
    
    std::getline(file, line);
    m_snpLength = (line.size()+1)/2;
    if (maxLength  > 0 && maxLength < m_snpLength)
        m_snpLength = maxLength;
    while(std::getline(file, line))
        ++m_numSnps;
    
    m_snpDataSize = ::bitsetSize<PrimitiveType>(m_snpLength);
    m_snpDataSize64 = ::bitsetSize<uint64_t>(m_snpLength);
    m_snpDataSizeULL = ::bitsetSize<unsigned long long>(m_snpLength);
    
    /*
     * Allocate memory aligned to 128 bytes (cache line). Must be aligned to at least 32 bytes for required AVX instructions.
     */
    m_data = (PrimitiveType*) aligned_alloc(128, m_snpDataSize*m_numSnps*sizeof(PrimitiveType));
    
    for (size_t i = 0; i < this->m_snpDataSize*this->m_numSnps; ++i)
    {
        m_data[i] = ZERO;
    }
    
    file.clear();
    file.seekg(0, std::ios::beg);
    
    for (size_t i = 0; i < m_numSnps; ++i)
    {
        std::getline(file, line);
        if (line.size() > 0)
        {
            convert<unsigned long long>(line.c_str(), (unsigned long long*) (&m_data[this->m_snpDataSize*i]), maxLength);
        }
    }
    return true;
}
Example #28
0
void TimgFilterTimesmooth::done(void)
{
    if (accumY) {
        aligned_free(accumY);
    }
    accumY = NULL;
    if (accumU) {
        aligned_free(accumU);
    }
    accumU = NULL;
    if (accumV) {
        aligned_free(accumV);
    }
    accumV = NULL;
    if (tempU[0]) {
        aligned_free(tempU[0]);
    }
    tempU[0] = NULL;
    if (tempU[1]) {
        aligned_free(tempU[1]);
    }
    tempU[1] = NULL;
    if (tempU[2]) {
        aligned_free(tempU[2]);
    }
    tempU[2] = NULL;
    if (tempV[0]) {
        aligned_free(tempV[0]);
    }
    tempV[0] = NULL;
    if (tempV[1]) {
        aligned_free(tempV[1]);
    }
    tempV[1] = NULL;
    if (tempV[2]) {
        aligned_free(tempV[2]);
    }
    tempV[2] = NULL;
}
void TimgFilterLogoaway::Tplane::done(void)
{
    if (bordn) {
        aligned_free(bordn);
    }
    bordn=NULL;
    if (bords) {
        aligned_free(bords);
    }
    bords=NULL;
    if (borde) {
        aligned_free(borde);
    }
    borde=NULL;
    if (bordw) {
        aligned_free(bordw);
    }
    bordw=NULL;
    if (vd) {
        aligned_free(vd);
    }
    vd=NULL;
    if (vt) {
        aligned_free(vt);
    }
    vt=NULL;
    if (uwetable) {
        aligned_free(uwetable);
    }
    uwetable=NULL;
    if (uweweightsum) {
        aligned_free(uweweightsum);
    }
    uweweightsum=NULL;
    if (shapexy_cn) {
        aligned_free(shapexy_cn);
    }
    shapexy_cn=NULL;
}
Example #30
0
int stop()
{
	for (size_t i = 0; i < terminals.size(); i++)
		if (terminals[i].online)
			close_connection(&terminals[i]);

	config_destroy();

	jparse_destroy();

	if (id != NULL)
		aligned_free(id);

	api_log_printf("[AK306] Stopped\r\n");

	return 0;
}