本文整理汇总了C++中split_block函数的典型用法代码示例。如果您正苦于以下问题:C++ split_block函数的具体用法?C++ split_block怎么用?C++ split_block使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_block函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: malloc
void *realloc(void *ptr, size_t size){
if (!ptr) {
return malloc(size);
}
if (valid_address(ptr)) {
size = align_pointer(size);
block_t block = get_block(ptr);
if (size <= block->size && BLOCK_SIZE_MIN <= block->size - size) {
split_block(block, size);
} else {
if (block->next && block->next->free && size <= BLOCK_SIZE + block->size + block->next->size) {
//merge möglich
merge_block(block);
if (BLOCK_SIZE_MIN <= block->size - size) {
split_block(block, size);
}
} else {
//real malloc
void *newptr = malloc(size);
if (!newptr) {
perror("error at realloc");
return NULL;
}
block_t newblock = get_block(newptr);
copy_block(block, newblock);
free(block);
return newptr;
}
}
return ptr;
}
return 0;
}
开发者ID:sasvarizoli,项目名称:SNP15,代码行数:34,代码来源:malloc.c
示例2: page_type
t_block *search_freed_block(size_t size)
{
t_page *page;
t_block *b;
size_t mem_width;
t_page_type mal_type;
mal_type = page_type(size);
page = first_page();
b = NULL;
while (page != NULL)
{
if (page->type == mal_type)
b = search_freed_block_in_page(page, size);
if (b != NULL)
break ;
page = page->next;
}
if (b == NULL)
return (NULL);
mem_width = b->size + BLOCK_SIZE;
b->size = size;
split_block(b, mem_width);
b->is_free = 0;
return (b);
}
开发者ID:Albatroce,项目名称:malloc-42,代码行数:26,代码来源:malloc.c
示例3: mm_realloc
void* mm_realloc(void* ptr, size_t size)
{
#ifdef MM_USE_STUBS
return realloc(ptr, size);
#else
if(size==0){
free(ptr);
return ptr;
}
if(!ptr)
return malloc(size);
t_block last;
t_block b = valid_addr(ptr,&last);
if(!b)
return ptr;
size_t s = align4(size);
if(b->size >= s){
if(b->size > s+BLOCK_SIZE+4)
split_block(b,s);
return ptr;
}
void *new = malloc(s);
if(!new)
return NULL;
size_t i,s4,*sp,*newp;
s4=s/(sizeof(size_t));
sp=(size_t*)(p);
newp=(size_t*)(new);
for(i=0;i<s4;i++)
newp[i]=sp[i];
free(ptr);
return new;
//#error Not implemented.
#endif
}
开发者ID:lesego-reezy,项目名称:hw3,代码行数:35,代码来源:mm_alloc.c
示例4: mm_malloc
void* mm_malloc(size_t size)
{
#ifdef MM_USE_STUBS
return calloc(1, size);
#else
s_block_ptr block, last;
size_t s;
s = align4(size);
if(foot){
last = foot;
block = find_block(last, s);
if(block){
if((block->size - s) >= (BLOCK_SIZE + 4)) split_block(block, s);
block->free = 0;
}
else{
block = extend_heap(last, s);
if(!block) return NULL;
}
}
else{
block = extend_heap(NULL, s);
if(!block) return NULL;
foot = block;
}
return block->data;
//#error Not implemented.
#endif
}
开发者ID:lesego-reezy,项目名称:hw3,代码行数:32,代码来源:mm_alloc.c
示例5: allocate_new_space
void* allocate_new_space(size_t size)
{
void* extend_heap_ptr = NULL;
size_t one_time_alloc = find_one_time_sbrk_size(size);
extend_heap_ptr = sbrk(one_time_alloc);
MDIC(extend_heap_ptr) -> size = one_time_alloc;
MDIC(extend_heap_ptr) -> occupy = false;
free_list_add(extend_heap_ptr,size2order(MDIC(extend_heap_ptr)->size));
MDIC(extend_heap_ptr) -> area_head = extend_heap_ptr;
MDIC(extend_heap_ptr) -> area_end = extend_heap_ptr + one_time_alloc;
total_size += one_time_alloc;
if(heap_ptr == NULL) heap_ptr = extend_heap_ptr;
L(printf("allocate_new_space(): sbrked %zu bytes at loc %zu, total_size: %zu\n",
MDIC(extend_heap_ptr) -> size, (size_t)(extend_heap_ptr - heap_ptr) ,total_size));
if (MDIC(extend_heap_ptr) -> size >= size)
{
/* Split if necessary, then return */
if(size > MDIC(extend_heap_ptr)->size / 2) return extend_heap_ptr;
return split_block(extend_heap_ptr,size);
}
else
{
D( printf("new area %zu is smaller than the size %zu needed\n",one_time_alloc,size ) );
exit(0);
}
}
开发者ID:AdonisSaveYourLife,项目名称:cs241_mps,代码行数:32,代码来源:alloc.c
示例6: mem_get
long mem_get(long request){
long l = request;
long lidx = 0;
long idx = 2;
while(idx != 0){
if(get_length(idx) >= l && get_free(idx)){
/* Gat gevonden waar de aanvraag in past. */
lidx = idx;
l = get_length(idx);
break;
}
idx = get_next(idx);
}
if(lidx == 0){
/* Geen gat groot genoeg. */
return -1;
}else if(l == request){
/* Gat precies groot genoeg. */
mem[0] += request;
mem[1] += ADMIN_SIZE;
set_free(lidx, 0);
return lidx + ADMIN_SIZE;
}else{
/* Alleen een gat > request. */
return split_block(lidx, request);
}
}
开发者ID:TomPeerdeman,项目名称:OS2012,代码行数:30,代码来源:first-fit.c
示例7: find_fit
/**********************************************************
* find_fit
* Traverse the heap searching for a block to fit asize
* Return NULL if no free blocks can handle that size
* Assumed that asize is aligned
* Uses fit bit option
* If we find a block that is close to the request size (4*sizethreshold)
* we will use that block
* If we can't find a block close to request size then we return the closest
* size and split the block before using it
**********************************************************/
void * find_fit(size_t asize, int *list_broken)
{
if(asize>maxBlockSize1)
return NULL;
size_t bestfit = mem_heapsize();
size_t curfit;
void *bestfitptr = NULL;
void *free_bp;
int sizethreshold = 2*DSIZE;
for (free_bp = free_listp; free_bp != NULL; free_bp = *((void **)free_bp))
{
if (asize <= GET_SIZE(HDRP(free_bp)))
{
curfit = GET_SIZE(HDRP(free_bp)) - asize;
if (curfit < 4*sizethreshold) {
bestfitptr = free_bp;
break;
}
if (curfit < bestfit) {
bestfit = curfit;
bestfitptr = free_bp;
}
}
}
if ((bestfitptr != NULL) && (GET_SIZE(HDRP(bestfitptr)) - asize >= sizethreshold)) {
bestfitptr = split_block (bestfitptr, asize);
*list_broken = 1;
}
return bestfitptr;
}
开发者ID:chznight,项目名称:assn3-malloc,代码行数:42,代码来源:mm.c
示例8: list_for_each
list_for_each(p, heap) {
uint64_t start = (p->start + mask) & ~mask;
if (p->file_priv == NULL &&
start + size <= p->start + p->size)
return split_block(p, start, size, file_priv);
}
开发者ID:nido,项目名称:pscnv,代码行数:7,代码来源:nouveau_mem.c
示例9: 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
示例10: ShmemDynAlloc
/*
* ShmemDynAlloc
*/
void *
ShmemDynAlloc(Size size)
{
void *block = NULL;
Size padded_size;
size = Max(ALIGN(size), MIN_ALLOC_SIZE);
for (padded_size = 1; padded_size < size && padded_size <= 1024; padded_size *= 2);
size = Max(size, padded_size);
block = get_block(size);
if (block == NULL)
{
/*
* Don't request fewer than 1k from ShmemAlloc.
* The more contiguous memory we have, the better we
* can combat fragmentation.
*/
Size alloc_size = Max(size, MIN_SHMEM_ALLOC_SIZE);
block = ShmemAlloc(BLOCK_SIZE(alloc_size));
memset(block, 0, BLOCK_SIZE(alloc_size));
block = (void *) ((intptr_t) block + sizeof(Header));
init_block(block, alloc_size, true);
mark_allocated(block);
}
if (get_size(block) - size >= MIN_BLOCK_SIZE)
split_block(block, size);
Assert(is_allocated(block));
return block;
}
开发者ID:seco,项目名称:pipelinedb,代码行数:38,代码来源:shm_alloc.c
示例11: align8
//allocate memory
void *malloc(size_t size){
t_block newBlock, last;
size_t newSize = align8(size);
if(base){
last = (t_block) base;
newBlock = find_block(&last, newSize);
if(newBlock){
//can we split
if((newBlock->size - newSize) >= (OFFSET + PTR_SIZE)){
split_block(newBlock, newSize);
}
newBlock->block_free = false;
} else {
//Can't find block, try extending the heap
newBlock = extend_heap(last, newSize);
if(!newBlock){
//cannot extend heap
return 0x0;
}
}
} else {
//first call
newBlock = extend_heap(0x0, newSize);
if(!newBlock){
//failed to extend
return 0x0;
}
base = newBlock;
}
return newBlock->data;
}
开发者ID:VasilVasilev93,项目名称:Simple-Memory-Manager,代码行数:35,代码来源:MemoryManager.cpp
示例12: 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
示例13: malloc
void* malloc(size_t size)
{
block_t* block;
if(size <= 0)
return NULL;
unsigned char index;
size = adjust_size(size, &index);
if(index > K_VALUE)
return NULL;
if(!global_memory){ /*first time*/
global_memory = sbrk(1<<K_VALUE);
if(global_memory == (void*)-1)
return NULL;
block = global_memory;
block->reserved = 0;
block->kval = K_VALUE;
block->succ = NULL;
block->pred = NULL;
free_list[K_VALUE] = block;
}
block = reserve_first(index);
if(block)
return (block + 1);
unsigned char new_index = index;
while(!free_list[new_index] ){
++new_index;
if(new_index > K_VALUE)
return NULL;
}
while(new_index > index){
block = remove_first(new_index);
block->reserved = 0;
block->succ = NULL;
block->pred = NULL;
block_t* new_block = split_block(block);
--new_index;
block->succ = new_block;
new_block->pred = block;
free_list[new_index] = block;
}
block = reserve_first(index);
return (block+1);
}
开发者ID:thomasstrahl,项目名称:Skola,代码行数:59,代码来源:test.c
示例14: ALIGN
void *mm_malloc(size_t size) {
//The malloc routine which allocates free blocks
//if we are given zero size, then there's nothing to malloc!
if (size == 0) return NULL ;
int new_size = ALIGN(size + BLK_HDR_FTR_SIZE);
//check if there's a free block that will contain that size
blockHdr *free_block = find_fit(new_size);
if (free_block == NULL ) {
//if there's no free block, then create one!
//But keep track of epilogue before calling sbrk()!
blockHdr *epilogue = GET_EPILOGUE;
epilogue->size = BLK_HDR_SIZE;
//call sbrk to get more space
free_block = mem_sbrk(new_size + BLK_HDR_SIZE);
//if there's an error return NULL
if (free_block <= 0)
return NULL ;
//get the start of the freeblock
free_block = (blockHdr *) ((char *) free_block - epilogue->size);
//free_block size taking epilogue into account
free_block->size = ((epilogue->size) + new_size) | 1;
//now set the footer size of the newly created block
blockFtr *ftr = (blockFtr *) ((char *) free_block - BLK_FTR_SIZE + ((free_block->size) & ~1));
ftr->size = free_block->size;
//adjust the epilogue
epilogue = GET_EPILOGUE;
epilogue->next_p = epilogue;
epilogue->prior_p = epilogue;
epilogue->size = BLK_HDR_SIZE | 1;
} else {
//otherwise, use the free block!
//if there's too much space, split the space and put remainder in appropriate free list
free_block = split_block(free_block->size, new_size, free_block);
//use the space you now have
free_block->size |= 1;
blockFtr *ftr = (blockFtr *) ((char *) free_block - BLK_FTR_SIZE + ((free_block->size) & ~1));
ftr->size |= 1; //set footer to allocated
//and remove the free block from the doubly linked list
remove_from_free_lists(free_block);
}
return (void *) ((char *) free_block + BLK_HDR_SIZE);
}
开发者ID:201201113,项目名称:dynamic-memory-allocator,代码行数:59,代码来源:mm.c
示例15: split_block_and_df_analyze
static basic_block
split_block_and_df_analyze (basic_block bb, rtx insn)
{
basic_block next;
next = split_block (bb, insn)->dest;
df_analyze ();
return next;
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:8,代码来源:rtl-factoring.c
示例16: my_malloc
/* Allocate _length number of bytes of free memory and returns the
address of the allocated portion. Returns 0 when out of memory. */
extern Addr my_malloc(unsigned int _length) {
// Round up to the size we need
int needed_size = basic_logarithm(_length);
// Check if there is already a free block of the needed size
if (freelist[needed_size][0] != NULL) {
// There is already a block free
Header* available = freelist[needed_size][0];
remove_header(available);
available->is_allocated = true;
return (void*) get_free_space(available);
}
else {
// There isn't a block free
// We need to break up a bigger block
// Find the smallest available
int power = needed_size + 1;
while (power < 32 && freelist[power][0] == NULL) {
power++;
}
if (power == 32) {
// No block big enough free
//printf("None big enough\n");
return NULL;
}
assert(freelist[power][0] != NULL);
Header* header, *split;
while (freelist[needed_size][0] == NULL) {
header = freelist[power][0];
remove_header(header);
split = split_block(header);
if (header == split) {
// Block can't split further
header->is_allocated = true;
return get_free_space(header);
}
else if (split == NULL) {
// Split failed
return NULL;
}
else {
header->size -= 1;
split->size = header->size - 1;
add_header(header);
add_header(split);
}
power--;
}
// We have a block ready
Header* ready = freelist[needed_size][0];
remove_header(ready);
ready->is_allocated = true;
return get_free_space(ready);
}
}
开发者ID:m-harper,项目名称:MemoryAllocator,代码行数:59,代码来源:my_allocator.c
示例17: free_list_init
/**
* Allocate memory block
*
* Allocates a block of size bytes of memory, returning a pointer to the
* beginning of the block. The content of the newly allocated block of
* memory is not initialized, remaining with indeterminate values.
*
* @param size
* Size of the memory block, in bytes.
*
* @return
* On success, a pointer to the memory block allocated by the function.
*
* The type of this pointer is always void*, which can be cast to the
* desired type of data pointer in order to be dereferenceable.
*
* If the function failed to allocate the requested block of memory,
* a null pointer is returned.
*
* @see http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/
*/
void *malloc(size_t size)
{
if(size<=0) return NULL;
if(free_list_ptr == NULL)
free_list_ptr = free_list_init();
L( actual_size += size);
size_t size_plus_dic = find_new_alloc_size(size);
void *block_ptr = block_available(size_plus_dic);
if (block_ptr == NULL)
{
/* Allocate new space from sbrk() */
block_ptr = allocate_new_space(size_plus_dic);
D(printf("malloc(): find new space at loc %zu with length %zu, occupy:%d\n",
(size_t)(block_ptr - heap_ptr),MDIC(block_ptr)->size,
MDIC(block_ptr)->occupy ));
// store the size_plus_dic into the block
MDIC(block_ptr) -> occupy = true;
free_list_delete(block_ptr , size2order( MDIC(block_ptr)->size )); // delete from free list.
L( printf("size actual_size total_size: %zu %zu %zu\n",size,actual_size,total_size) );
return block_ptr + sizeof(mem_dic);
}
else
{
if (MDIC(block_ptr)->size > size_plus_dic)
block_ptr = split_block(block_ptr,size_plus_dic);
if ( !block_ptr || MDIC(block_ptr)->size != size_plus_dic){
D( printf("Error in malloc(): size after split cannot match\n") );
return NULL;
}
/* Assign the size to the block, split the block if necessary */
D( printf("malloc(): find old space at loc %zu with length %zu, occupy:%d\n",
(size_t)(block_ptr - heap_ptr),MDIC(block_ptr)->size,
MDIC(block_ptr)->occupy ) );
MDIC(block_ptr) -> occupy = true;
free_list_delete(block_ptr,size2order( MDIC(block_ptr)->size ));
L( printf("size actual_size total_size: %zu %zu %zu\n",size,actual_size,total_size) );
return block_ptr + sizeof(mem_dic);
}
return NULL;
}
开发者ID:AdonisSaveYourLife,项目名称:cs241_mps,代码行数:76,代码来源:alloc.c
示例18: list_for_each
static struct mem_block *alloc_block(struct mem_block *heap, int size,
int align2, struct drm_file *file_priv)
{
struct mem_block *p;
int mask = (1 << align2) - 1;
list_for_each(p, heap) {
int start = (p->start + mask) & ~mask;
if (p->file_priv == 0 && start + size <= p->start + p->size)
return split_block(p, start, size, file_priv);
}
开发者ID:PennPanda,项目名称:linux-repo,代码行数:11,代码来源:radeon_mem.c
示例19: remove_exits_and_undefined_stmts
static bool
remove_exits_and_undefined_stmts (struct loop *loop, unsigned int npeeled)
{
struct nb_iter_bound *elt;
bool changed = false;
for (elt = loop->bounds; elt; elt = elt->next)
{
/* If statement is known to be undefined after peeling, turn it
into unreachable (or trap when debugging experience is supposed
to be good). */
if (!elt->is_exit
&& wi::ltu_p (elt->bound, npeeled))
{
gimple_stmt_iterator gsi = gsi_for_stmt (elt->stmt);
gcall *stmt = gimple_build_call
(builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0);
gimple_set_location (stmt, gimple_location (elt->stmt));
gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
split_block (gimple_bb (stmt), stmt);
changed = true;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Forced statement unreachable: ");
print_gimple_stmt (dump_file, elt->stmt, 0, 0);
}
}
/* If we know the exit will be taken after peeling, update. */
else if (elt->is_exit
&& wi::leu_p (elt->bound, npeeled))
{
basic_block bb = gimple_bb (elt->stmt);
edge exit_edge = EDGE_SUCC (bb, 0);
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Forced exit to be taken: ");
print_gimple_stmt (dump_file, elt->stmt, 0, 0);
}
if (!loop_exit_edge_p (loop, exit_edge))
exit_edge = EDGE_SUCC (bb, 1);
gcc_checking_assert (loop_exit_edge_p (loop, exit_edge));
gcond *cond_stmt = as_a <gcond *> (elt->stmt);
if (exit_edge->flags & EDGE_TRUE_VALUE)
gimple_cond_make_true (cond_stmt);
else
gimple_cond_make_false (cond_stmt);
update_stmt (cond_stmt);
changed = true;
}
}
return changed;
}
开发者ID:0day-ci,项目名称:gcc,代码行数:53,代码来源:tree-ssa-loop-ivcanon.c
示例20: split_block
static struct mem_block *alloc_block(struct mem_block *heap, int size,
int align2, struct drm_file *file_priv)
{
struct mem_block *p;
int mask = (1 << align2) - 1;
for (p = heap->next; p != heap; p = p->next) {
int start = (p->start + mask) & ~mask;
if (p->file_priv == NULL && start + size <= p->start + p->size)
return split_block(p, start, size, file_priv);
}
return NULL;
}
开发者ID:jobi,项目名称:drm-psb,代码行数:14,代码来源:i915_mem.c
注:本文中的split_block函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论