// allocate s bytes within region r void * _reap_malloc(struct _ReapHandle *r, _AliasQualHandle_t aq, unsigned int s) { void *result; if(r->curr == NULL) { //grab a page, and hold onto a ref. We need to free it later void *p =malloc(default_region_page_size+sizeof(struct _ReapPage)); if(!p) throw(1) r->curr = (struct _ReapPage*)p; r->curr->bget_page = (p + sizeof(struct _ReapPage)); r->curr->next = NULL; //pass the page to bget r->bkey = bget_init_region(r->curr->bget_page, default_region_page_size); if(!r->bkey) throw(2) r->bkey->priv = r; // direct allocation for large buffers is a pain ... revisit // no direct allocation means there is no need for a release function // no compaction, default size for acquisition request is page_size+ bectl(r->bkey, NULL, _acquire_reap_page, NULL, default_region_page_size); } if(aq == CYC_CORE_REFCNT_AQUAL) { result = bgetz(r->bkey, (bufsize)(s + sizeof(int))); if(!result) throw(3) *((int*)result) = 1; result += sizeof(int); return (void*)result; } else { result = bgetz(r->bkey, (bufsize)s); if(!result) throw(4) return (void*)result; } }
laser_packet* lp_alloc(packet_data* data) { if (data == NULL) { return NULL; } uint16_t aligned_size = align_size(sizeof(laser_packet)); laser_packet* lp = bgetz(aligned_size); if (lp == NULL) { return NULL; } lp->data = data; lp->data_size = data->total_size; return lp; }
static void *raw_calloc(size_t hdr_size, size_t ftr_size, size_t pl_nmemb, size_t pl_size) { size_t s = hdr_size + ftr_size + pl_nmemb * pl_size; void *ptr = NULL; raw_malloc_validate_pools(); /* Check wrapping */ if (s < pl_nmemb || s < pl_size) goto out; /* BGET doesn't like 0 sized allocations */ if (!s) s++; ptr = bgetz(s); out: raw_malloc_return_hook(ptr, pl_nmemb * pl_size); return ptr; }
inline void *calloc(size_t n, size_t size) { return bgetz((long long int)n * size); }