By: Mark Roulo (nothanks.delete@this.xxx.com), June 30, 2022 8:25 am
Room: Moderated Discussions
Foo_ (foo.delete@this.nomail.com) on June 30, 2022 7:43 am wrote:
> Adrian (a.delete@this.acm.org) on June 30, 2022 5:36 am wrote:
> >
> > In the memory allocators used by individual processes it is possible to completely avoid
> > memory fragmentation, e.g. by using separate memory pools for different object sizes.
>
> That doesn't make sense. Memory fragmentation is typically caused by differing
> *lifetimes* of heap allocations, not by differing object sizes.
>
It is both.
All the allocations the same size (e.g. 1KB) mean there is no
fragmentation because if you have enough memory for all your
objects then there will be a slot. You won't have a situation
where you need 1KB, have 5KB, but the 5KB is unusable because it
is in 100 discontiguous 50B pieces.
Alternately, if one wants to allocate a large number of randomly
sized objects and then free them all at once (and you know this ...)
then you can avoid fragmentation by simply allocating "from the end"
and freeing by "resetting the 'next'" pointer.
The intersection of different sizes and different lifetimes (and
not knowing them up front ...) creates the fragmentation.
> Adrian (a.delete@this.acm.org) on June 30, 2022 5:36 am wrote:
> >
> > In the memory allocators used by individual processes it is possible to completely avoid
> > memory fragmentation, e.g. by using separate memory pools for different object sizes.
>
> That doesn't make sense. Memory fragmentation is typically caused by differing
> *lifetimes* of heap allocations, not by differing object sizes.
>
It is both.
All the allocations the same size (e.g. 1KB) mean there is no
fragmentation because if you have enough memory for all your
objects then there will be a slot. You won't have a situation
where you need 1KB, have 5KB, but the 5KB is unusable because it
is in 100 discontiguous 50B pieces.
Alternately, if one wants to allocate a large number of randomly
sized objects and then free them all at once (and you know this ...)
then you can avoid fragmentation by simply allocating "from the end"
and freeing by "resetting the 'next'" pointer.
The intersection of different sizes and different lifetimes (and
not knowing them up front ...) creates the fragmentation.