[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Memory allocation for userdata
- From: liam mail <liam.list@...>
- Date: Fri, 16 Dec 2011 11:37:34 +0100
On Friday, 16 December 2011, Dirk Laurie <firstname.lastname@example.org> wrote:
> Back in my youth we were told not to do that when the application, as
> this one does, only frees the structures right at the end. Instead we
> were supposed to allocate a memory heap, reallocate it to double size
> when it gets exhausted, and write a function `alloc` that simply
> serves up bits off that heap.
> I've been out of C for, oh, twelve years I suppose, and it occurs to
> me that in the meantime the algorithm behind `calloc` might have
> become clever enough to do just that, one heap per process.
This is not that far off what the heap is in a process or what a block allocator does (besides the doubling, which instead would be a page).
What is it that you believe calloc does? Generally it grabs a chunk from the memory allocator which will be zero initialised before it is used, although it is not quite as simple as this and may use _tricks_.