Click here to Skip to main content
16,017,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Want to implement a memory pool, from which I can get any size of data object without wastage of memory like internal or external fragmentation. Any approach or ideas, you have then tell me.

What I have tried:

My approach is fixed the size of memory pool in bytes, and store an initial pointer, After that what size of data comes allocate size from memory pool and move the pointer to next free address i.e ptr+size.
Posted

1 solution

If you are looking for guidance around creating your own memory pool, the example in this article[^] showcases a simple way to implement a pool. When I read this article, I was surprised how simple and clean the author made it. Obviously, the implementation isn't 100% complete and shows that there are a lot of further operations that could be added, but this would be a great way to get started.
 
Share this answer
 
Comments
Member 16287282 18-Jun-24 3:22am    
This article introduce about same data-type memory pool, Like when we initialise our pool, it creates of single data type. I want to implement a pool in which I can store any data type (like int, float, string, object etc...). If you want my approach I will send you, if you give me your mail id or something else.
Pete O'Hanlon 18-Jun-24 3:40am    
Sounds like you want to also implement a VARIANT type of entity. https://learn.microsoft.com/en-us/windows/win32/winauto/variant-structure
Member 16287282 20-Jun-24 1:16am    
Didn't Get any Approach or Solution? Can you provide more about my Problem Statement?
I have to implement Memory pool for various Data types, Like I create a memory pool, and want to allocate memory from this pool to any data type. Data type may be int, float, double, an object of any class .... etc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900