473,883 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looking for an open source memory pool

hi,

I'm looking for an open source memory pool. It's for use on an
embedded system, if that makes any difference. Something with garbage
collection/defragmentation would be nice. It should have the ability
to allocate different size chunks of memory not just a single size. It
should error check for double free, etc. And it should be usable by a
mixture of C and C++ subsystems.

If I get that, I'm happy. Thank you very much.

As a bonus, I'd like to detect memory leaks, although I'm willing to
code that bit myself to get what I want (I just don't want to reinvent
the wheel of a standard memory pool).

I see two approaches to detecting leaks. Both involve the memory pool
actually allocating more memory than was requested and keeping a
secret header for itself where it stores details of the caller (file/
line number or unique ID, plus timestamp).

After each unit test I would generally expect any allocated memory to
be freed, so comapring memory pool free size at start and end of test
should suffice. If I know that the test will cause my software to
allocate but not free some memory, I can adjust for that (for
instance, Software Under Test allocates a buffer to send a message
which will be freed by recipient, or a timer data block, or similar).

So much for unit test, which ought to be straightforward . Integration
& system verification test are more complex, with lots of background
tasks running. However, in an embedded system it is uncommon for
memory to remain allocated for long. So I can create a low priority
task which runs when the system is otherwise idle and checks
timestamps, looking for memory allocated for "a suspiciously long
time", which can then be investigated to see if someone forgot to free
it. Not perfect, but more than good enough.

Any comments? And any basic, Open Source, memory pool which I can use
as a base?

Thanks in advance...

Jul 25 '08 #1
16 5110
On Jul 25, 9:34*am, graham.keelli.. .@gmail.com wrote:
hi,

* I'm looking for an open source memory pool. It's for use on an
embedded system, if that makes any difference. Something with garbage
collection/defragmentation would be nice. It should have the ability
to allocate different size chunks of memory not just a single size. It
should error check for double free, etc. And it should be usable by a
mixture of C and C++ subsystems.

If I get that, I'm happy. Thank you very much.

As a bonus, I'd like to detect memory leaks, although I'm willing to
code that bit myself to get what I want (I just don't want to reinvent
the wheel of a standard memory pool).

I see two approaches to detecting leaks. Both involve the memory pool
actually allocating more memory than was requested and keeping a
secret header for itself where it stores details of the caller (file/
line number or unique ID, plus timestamp).

After each unit test I would generally expect any allocated memory to
be freed, so comapring memory pool free size at start and end of test
should suffice. If I know that the test will cause my software to
allocate but not free some memory, I can adjust for that (for
instance, Software Under Test allocates a buffer to send a message
which will be freed by recipient, or a timer data block, or similar).

So much for unit test, which ought to be straightforward . Integration
& system verification test are more complex, with lots of background
tasks running. However, in an embedded system it is uncommon for
memory to remain allocated for long. So I can create a low priority
task which runs when the system is otherwise idle and checks
timestamps, looking for memory allocated for "a suspiciously long
time", which can then be investigated to see if someone forgot to free
it. Not perfect, but more than good enough.

Any comments? And any basic, Open Source, memory pool which I can use
as a base?

Thanks in advance...
Bosst++ is looking good. See
http://www.boost.org/doc/libs/1_35_0...d_storage.html
Jul 25 '08 #2
gr************* *@gmail.com wrote:
Something with garbage collection/defragmentation would be nice.
As a bonus, I'd like to detect memory leaks
Aren't those two things a bit mutually exclusive?
Jul 25 '08 #3
On 2008-07-25 10:02:43 -0400, Juha Nieminen <no****@thanks. invalidsaid:
gr************* *@gmail.com wrote:
>Something with garbage collection/defragmentation would be nice.
>As a bonus, I'd like to detect memory leaks

Aren't those two things a bit mutually exclusive?
No. When the application terminates, all reachable memory has been leaked.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 25 '08 #4
On Jul 25, 5:03 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-25 10:02:43 -0400, Juha Nieminen <nos...@thanks. invalidsaid:
graham.keelli.. .@gmail.com wrote:
Something with garbage collection/defragmentation would be nice.
As a bonus, I'd like to detect memory leaks
Aren't those two things a bit mutually exclusive?
No. When the application terminates, all reachable memory has
been leaked.
We must have a different definition of memory leaks. When I
terminate an application program, the system recovers all of the
memory, so no memory leaks. The problem with memory leaks is
when the program doesn't terminate, but just keeps on using more
and more memory. (And such leaks are perfectly possible with
garbage collection, just not as likely.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 25 '08 #5
On 2008-07-25 17:10:38 -0400, James Kanze <ja*********@gm ail.comsaid:
On Jul 25, 5:03 pm, Pete Becker <p...@versatile coding.comwrote :
>On 2008-07-25 10:02:43 -0400, Juha Nieminen <nos...@thanks. invalidsaid:
>>graham.keelli ...@gmail.com wrote:
Something with garbage collection/defragmentation would be nice.
>>>As a bonus, I'd like to detect memory leaks
>>Aren't those two things a bit mutually exclusive?
>No. When the application terminates, all reachable memory has
been leaked.

We must have a different definition of memory leaks. When I
terminate an application program, the system recovers all of the
memory, so no memory leaks.
Nevertheless, the program leaked memory, leaving it for the OS to clean
up. Yes, from a system perspective, the memory probably wasn't lost,
but that's a different issue.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 25 '08 #6
On Jul 26, 12:14 am, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-25 17:10:38 -0400, James Kanze <james.ka...@gm ail.comsaid:
On Jul 25, 5:03 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-25 10:02:43 -0400, Juha Nieminen <nos...@thanks. invalidsaid:
>graham.keelli. ..@gmail.com wrote:
Something with garbage collection/defragmentation would be nice.
>Aren't those two things a bit mutually exclusive?
No. When the application terminates, all reachable memory has
been leaked.
We must have a different definition of memory leaks. When I
terminate an application program, the system recovers all of the
memory, so no memory leaks.
Nevertheless, the program leaked memory, leaving it for the OS
to clean up.
Again, it depends on your definition of leaked. As a pragmatic
developer, the only definition which interests me is the one
that concerns me: the program hasn't "freed" memory that it
doesn't need anymore. If a garbage collector is present, and
could collect the memory, it isn't "leaked" (since the
application could reuse it). If its a one time operation, for
example constructing a singleton which is never deleted, it
isn't leaked (any more than a static variable is a "leak"). If
the application keeps memory that it doesn't need any more, even
if it does have a pointer to it, and could reach it (e.g. it's
in a map, indexed by a key that has been retired, and won't be
used any more), it's been leaked.

I rather insist on this definition, because people use all sort
of useless definitions, to prove that you can't have a memory
leak in Java (although Sun has had a couple in their bug list),
or some other claim that is only true because the definition is
useless.

(Of course, even this definition leaves some questions open. A
simple compiler will parse all of the source first, then
generate code. Once the source is parsed, no more error
messages will appear. Has it leaked memory because the buffer
of std::cerr hasn't been freed? It's not going to use it any
more.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 26 '08 #7
On 2008-07-26 04:57:07 -0400, James Kanze <ja*********@gm ail.comsaid:
On Jul 26, 12:14 am, Pete Becker <p...@versatile coding.comwrote :
>On 2008-07-25 17:10:38 -0400, James Kanze <james.ka...@gm ail.comsaid:
>>On Jul 25, 5:03 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-25 10:02:43 -0400, Juha Nieminen <nos...@thanks. invalidsa
id:
>>>>graham.keel li...@gmail.com wrote:
>Somethin g with garbage collection/defragmentation would be nice.
>>>>Aren't those two things a bit mutually exclusive?
>>>No. When the application terminates, all reachable memory has
been leaked.
>>We must have a different definition of memory leaks. When I
terminate an application program, the system recovers all of the
memory, so no memory leaks.
>Nevertheless , the program leaked memory, leaving it for the OS
to clean up.

Again, it depends on your definition of leaked.
Yes, that was my point.
As a pragmatic
developer, the only definition which interests me is the one
that concerns me: the program hasn't "freed" memory that it
doesn't need anymore.
And one way to see that is to terminate the program and look at what's
still in use.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 26 '08 #8
On Jul 26, 12:55 pm, Pete Becker <p...@versatile coding.comwrote :
On 2008-07-26 04:57:07 -0400, James Kanze <james.ka...@gm ail.comsaid:
[...]
As a pragmatic
developer, the only definition which interests me is the one
that concerns me: the program hasn't "freed" memory that it
doesn't need anymore.
And one way to see that is to terminate the program and look
at what's still in use.
Which begs the point: what does it mean to be "still in use"?
If there is an active pointer to it, is it "still in use" (even
if the application would never have used that pointer)?

Purify (and I suppose most other similar tools) distinguishes
between a "memory leak" (no pointer to the memory, but it hasn't
been freed) and a "possible memory leak" (unfreed memory at the
end of the program, but still pointers to it in static memory).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 26 '08 #9
On 2008-07-26 08:02:33 -0400, James Kanze <ja*********@gm ail.comsaid:
On Jul 26, 12:55 pm, Pete Becker <p...@versatile coding.comwrote :
>On 2008-07-26 04:57:07 -0400, James Kanze <james.ka...@gm ail.comsaid:

[...]
>>As a pragmatic
developer, the only definition which interests me is the one
that concerns me: the program hasn't "freed" memory that it
doesn't need anymore.
>And one way to see that is to terminate the program and look
at what's still in use.

Which begs the point: what does it mean to be "still in use"?
Sigh. As I said before, still reachable.
If there is an active pointer to it, is it "still in use" (even
if the application would never have used that pointer)?

Purify (and I suppose most other similar tools) distinguishes
between a "memory leak" (no pointer to the memory, but it hasn't
been freed) and a "possible memory leak" (unfreed memory at the
end of the program, but still pointers to it in static memory).
Shrug. The original question was, in essence, how can garbage
collection help detect leaks, not what's the best possible approach to
leak detection. I answered the first question, and you're talking about
the second one.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jul 26 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
6868
by: Tron Thomas | last post by:
As part of applying for a programming position at a company, I recently I had submitted some code samples to one of the developers for review. This is the feedback I received: One of his concerns was frequent calls to new and delete, which can cause memory fragmentation over time. An example is the allocation and destruction
22
3496
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from application server, will each connection take the memory 800M (200000 x 4k = 800 M), so the memory took will be 800M times number of connections, or the total memory get from bufferpool will be 800M?
5
7020
by: bull | last post by:
hi could any one explain with example the following in a better way to understand 1. what is stack in memory, how the programs are stored in stack , what is the use of stack 2. What is heap in memory, how the programs are stored in heap , what is the use of heap 3. what is pool memory otherwise memory pool, what is the use of memory pool 4. what is difference between stack and heap
10
2116
by: Markus.Elfring | last post by:
Some APIs/SDKs are available to modify settings like "readable", "writeable" or "executeable". Examples: - http://msdn.microsoft.com/library/en-us/memory/base/memory_protection_constants.asp - http://www.opengroup.org/onlinepubs/009695399/functions/mprotect.html - http://en.wikipedia.org/wiki/PaX Would a companion function fit to the "realloc" programming interface to
6
8590
by: B B | last post by:
Okay, here is what's happening: I have a reasonably fast laptop (1.4 GHz Mobile M, so comparable to 2.5GHz P4) doing .net development. Running Windows XP pro, SP2 IIS is installed and running fine All SQL Servers I am referring to share a small (10 computers or so) LAN with a 100MB Switch. No other computers on the LAN exhibit this problem.
4
4386
by: Nevyn Twyll | last post by:
I've been working on an asp.net application and everything's been great. But suddenly, whether I'm tyring to use a database on my own machine, or on my server, I'm getting a timeout when trying to open a database connection. The error seems to happen regardless of what ASP.NET app I'm working with/trying to debug. It will open a few connections, Here's the error:
29
7099
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's current state is connecting. I'm very puzzled since I'm not calling "ExecuteNonQuery" and I am calling "Open", which I've always assumed was Synchronous, i.e. would not return until either A) the connection was open or B) there was an error. Here...
34
2605
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do? Contrary to some people that will start crying to that &@@""#~ programmer that wrote this sh!!!! you keep your cool and you do the following:
6
2571
by: CANCER.0707 | last post by:
The problem statement is as follows Create a library that creates pools of memory of different sizes.For e.g. one pool of 32 byte size, another pool of 64 byte size and so on.Create an array of pointers and store the pointer to each pool in this array.Each pool maintains one link list of free pointers and another link list of allocated pointers.Whenever, the main program requests for a memeory of say, size 32 bytes, a pointer is returned...
0
9932
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
11112
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10833
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
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7959
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
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
5784
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...
1
4602
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
3
3228
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.