Skip to content

Use memory blocks instead of one byte allocations#8

Open
ansiwen wants to merge 3 commits intomattn:masterfrom
ansiwen:memblocks
Open

Use memory blocks instead of one byte allocations#8
ansiwen wants to merge 3 commits intomattn:masterfrom
ansiwen:memblocks

Conversation

@ansiwen
Copy link
Copy Markdown

@ansiwen ansiwen commented Sep 5, 2020

The allocation of one byte usually uses a lot more memory in reality, typically 32 Bytes. This change uses memory blocks which act as pools of pointers, so that each pointer really only consumes one byte. It also enables module-aware mode and adds some unit tests.

The allocation of one byte usually uses a lot more memory in reality,
typically 32 Bytes. This change uses memory blocks which act as pools
of pointers, so that each pointer really only consumes one byte.

Signed-off-by: Sven Anderson <sven@anderson.de>
Signed-off-by: Sven Anderson <sven@anderson.de>
Signed-off-by: Sven Anderson <sven@anderson.de>
@cybercrimineel
Copy link
Copy Markdown

You make a fair point, I think further optimization is possible though. A pointer being allocated simply indicates a value exists, which can be referenced using that pointer. This reference doesn't have to be an actual pointer, it could simply be an index into an array of bits, which indicate whether a value referenced using that bit's index exists or not. This array of bits can be expanded using realloc, preventing the excess memory allocation.

I believe this would also solve the problem, while consuming just a single bit per value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants