Skip to content

Random allocate and deallocate objects in memory pool in chapter 4? #3

@yt7589

Description

@yt7589

I want to know how to deal with randomly allocate and deallocate in in memory pool in chapter 4. For example, I initialized a memory pool with initial size is 10. Then I allocate six objects. The memory pool will look as bellow:

index object_ is_free_
0 o1 false
1 o2 false
2 o3 false
3 o4 false
4 o5 false
5 o6 false
6 empty true
7 empty true
8 empty true
9 empty true

Then I deallocated the 3rd and 5th elements as bellow:

index object_ is_free_
0 o1 false
1 o2 false
2 empty true
3 o4 false
4 empty true
5 o6 false
6 empty true
7 empty true
8 empty true
9 empty true

If I allocate 4 objects it would as bellow:

index object_ is_free_
0 o1 false
1 o2 false
2 empty true
3 o4 false
4 empty true
5 o6 false
6 o7 false
7 o8 false
8 o9 false
9 o10 false

The the memory pool is full now. But it's 2, 4 index position is free. It the memory pool is large it will left many holes.

My question is:

  1. Is my understanding is right or not?
  2. If my understanding is right how to solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions