473,777 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cached memory allocators

4 New Member
I am dealing with internal memory fragmentation issues in my program (C++ program on freeBSD). It involves a large number of fixed-size structures.
For example for my records which are typically fixed at 100 bytes, the default allocator allocates 128 bytes (closest power of two) wasting 28 bytes per records and this adds up to a significant amount over several thousand records.

Before jumping in and writing my own custom allocator which grabs memory pages and carves out block-sizes of 100 bytes each, I wanted to look around and see what cached allocators are available out there.

I came across allocators such as the mt-allocator in libstdc++, but the problem is that it is still a power-of-two allocator i.e. it pre-allocates only in blocks sizes 2,4,8,16,32, etc. which is exactly what I am trying to avoid.

Does anyone have experience with (or recommendations for) cached allocators where the client can specify the cache structure & size in advance (sort of like BSD memory allocator: http://docs.freebsd.or g/44doc/papers/kernmalloc.html ).
I am working in a multi-threaded environment and hence performance of the allocator is important as well.
Sep 6 '07 #1
3 2077
weaknessforcats
9,208 Recognized Expert Moderator Expert
Have you considered using placement new??

You allocate a buffer using new and then allocate items in the buffer byusing placement new.
Sep 7 '07 #2
RRick
463 Recognized Expert Contributor
Replacement new? That's a new term for me. I'm just going to clarify part of what W4cats said.

Each class has an operator new that can be overriden. This is similar to the operator=, where the compiler supplies a default one which you can override. In this case, the class new uses the global new to create a big pool of objects that are then farmed out.

If you make a class new, you also need to make a matching class delete.
Sep 7 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Replacement new?
No. Placement new not replacement new.

Placement new is used when you specify the location where the allocation is to be made. It is used when you write your own memory managers.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     char buffer[1024];
  4.  
  5.     int* i = new(buffer) int[5];
  6.  
  7. }
  8.  
Here a local 1K buffer is allocated and the new places the array of 5 ints in that buffer. It's now up to you to manage what goes on in buffer.
Sep 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
1862
by: Jakob Bieling | last post by:
Hi, Whenever allocating memory using operator new or operator new I feel like I should only use it very sparingly, because otherwise memory is wasted (by additional overhead needed to manage all those allocations) which also loses some performance. I am specifically talking about many little allocations (approx. 16-512 bytes). Is my feeling about this justified? thanks! --
18
6681
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a hard drive file system. Over time, the more often use call new/delete or alloc/free, there will be gaps and fragments in the heap. This can lead to inefficient use of available memory, as well as cache-hit inefficiencies.
7
2293
by: Felix E. Klee | last post by:
Hi, why does the memory consumption of the program attached below increase steadily during execution? Shouldn't vector::reserve() allocate one large memory chunk of memory that doesn't change anymore? CPU: Pentium III Coppermine (Celeron) OS: Slackware LINUX 9.1 with kernel 2.4.22 Compiler: 3.2.3 Compile command: g++ -O0 -o foo foo.cpp
11
2664
by: aaaaa | last post by:
Hi all, Does anybody know if STLPort or SGI STL standard allocators do memory pooling for the list, map and set? Also I have had a look at the BOOST pool_alloc (to be used as a pooling allocator for lists), but looking into the code it doesn't seem to ever release (to the global ::free) the memory that was once allocated. I can understand that such memory can be re-used if I have another list
14
8220
by: phil_gg04 | last post by:
Dear C++ Experts, Over the last couple of months I have been writing my first program using shared memory. It has been something of an "in-at-the-deep-end" experience, to say the least. At present the shared memory contains a few fixed-size structs, but I really need to be able to store more complex variable-sized data in there. So the next task is to work out how to store C++ objects, and if possible STL containers, in this shared...
13
2556
by: Ardhendu Nandan | last post by:
Hi, Will someone please tell me, How malloc allocating memory from heap & what data structure it is using to do so. regards Ardhendu
15
2599
by: CMOS | last post by:
one of the projects im working in currently requires use of ultra large sized maps, lists, vector, etc. (basically stl containers). Sizes might grow up to 1000 Million entries. since it is impossible to have all this data in memory, im planning to implement these containers to hold data both in memory and disk at the same time. im not sure this can be achieved using customer allocators and im wondering if there are any such...
19
1696
by: smarty | last post by:
how can I find the memory allocated dynamically? is there any possibility of finding it?
12
3004
by: David Given | last post by:
I have a situation where I need to be able to allocate chunks on unmapped virtual memory. Because the memory I'm allocating isn't mapped, I can't use a normal memory allocator, as most of them want to store their metadata about the free list in the unused holes in the heap. Instead, I need a memory allocator that stores its metadata out-of-line (perversely enough, a simple malloc() heap would be fine for that). Does anyone know of...
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.