473,385 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

boost::singleton_pool<...>::release_memory problem

As boost::pool_alloc use singleton holder for pool allocator, client
programmers have to reclaim the memory by hand through calling
singleton_pool<alloc_tag, elem_size>::purge_memory() or something to
release the memory, so the program should have knowledge of the
elem_size, sometime, it's impossible or at least hard to know the size
of the element allocated by the allocator.
for example:
struct my_tag
list<int, boost::pool_allocator<int List;
.....
boost::singleton_pool<boost::pool_allocator_tag,
sizeof(_List_node)>::release_memory()

Here _List_node is the real element that is dynamic created by
allocator, so if I use sizeof(int) instead, it does NOT work

Jul 10 '07 #1
3 3749
On 10 Jul, 03:37, Barry <dhb2...@gmail.comwrote:
As boost::pool_alloc use singleton holder for pool allocator, client
programmers have to reclaim the memory by hand through calling
singleton_pool<alloc_tag, elem_size>::purge_memory() or something to
release the memory, so the program should have knowledge of the
elem_size, sometime, it's impossible or at least hard to know the size
of the element allocated by the allocator.
for example:
struct my_tag
list<int, boost::pool_allocator<int List;
....
boost::singleton_pool<boost::pool_allocator_tag,
sizeof(_List_node)>::release_memory()

Here _List_node is the real element that is dynamic created by
allocator, so if I use sizeof(int) instead, it does NOT work
indeed, list uses rebind mechanism to define allocator to use.
_List_node is implementation detail and you should not use it.

I don't think there is a way to achieve that other than to extend
pool_allocator

something like
template <class T, ...>
class my_pool_allocator : public boost::pool_allocator<T, ...>
{
... forward constructors here

// rebind
template <typename U>
struct rebind
{
typedef my_pool_allocator<U, ...other;
};

bool release_memory() const
{
return ::boost::singleton_pool
< ::boost::pool_allocator_tag
, sizeof(T)
...
>::release_memory();
}
};

std::list<int, my_pool_allocator<int, ... list;
list.get_allocator().release_memory()
regards

DS


Jul 10 '07 #2
On 7 10 , 8 44 , dasjotre <dasjo...@googlemail.comwrote:
On 10 Jul, 03:37, Barry <dhb2...@gmail.comwrote:
As boost::pool_alloc use singleton holder for pool allocator, client
programmers have to reclaim the memory by hand through calling
singleton_pool<alloc_tag, elem_size>::purge_memory() or something to
release the memory, so the program should have knowledge of the
elem_size, sometime, it's impossible or at least hard to know the size
of the element allocated by the allocator.
for example:
struct my_tag
list<int, boost::pool_allocator<int List;
....
boost::singleton_pool<boost::pool_allocator_tag,
sizeof(_List_node)>::release_memory()
Here _List_node is the real element that is dynamic created by
allocator, so if I use sizeof(int) instead, it does NOT work

indeed, list uses rebind mechanism to define allocator to use.
_List_node is implementation detail and you should not use it.

I don't think there is a way to achieve that other than to extend
pool_allocator

something like
template <class T, ...>
class my_pool_allocator : public boost::pool_allocator<T, ...>
{
.. forward constructors here

// rebind
template <typename U>
struct rebind
{
typedef my_pool_allocator<U, ...other;
};

bool release_memory() const
{
return ::boost::singleton_pool
< ::boost::pool_allocator_tag
, sizeof(T)
...
>::release_memory();
}

};

std::list<int, my_pool_allocator<int, ... list;
list.get_allocator().release_memory()

regards

DS
As check out SGI and Dimkumware STL implementation, I found that they
neither rebind the XX_node(something like that) to be their
allocator_type, they separately provide _Buynod and _M_get_node to
create a node,

So the following code below in MSVC 8.0:

template <class T>
struct my_pool_allocator : pool_allocator<T{
my_pool_allocator() : pool_allocator<T>() {}
my_pool_allocator(my_pool_allocator<Tconst&) : pool_allocator<T>()
{}
my_pool_allocator(pool_allocator<Tconst&) {}

template <class U>
struct rebind {
typedef my_pool_allocator<Uother;
};

static bool release_memory()
{
return singleton_pool
< pool_allocator_tag
, sizeof(T)
>::release_memory();
}

};

int main(int argc, char* argv[])
{
typedef list<int, my_pool_allocator<int mylist;
mylist IntList;
cout << typeid(IntList.get_allocator()).name() << endl;
return 0;
}

produces the result:
struct my_pool_allocator<int>
and it really does not reclaim memory as I walk into the function

I don't konw the my_pool_allocator extension is right or not, but I
think it does not affect the result

So, if the container is not vector, it's hard to use
boost::pool_allocator and release_memory, if not hopeless

Thanks

Jul 10 '07 #3
On 10 Jul, 16:09, Barry <dhb2...@gmail.comwrote:
As check out SGI and Dimkumware STL implementation, I found that they
neither rebind the XX_node(something like that) to be their
allocator_type, they separately provide _Buynod and _M_get_node to
create a node,

So the following code below in MSVC 8.0:

template <class T>
struct my_pool_allocator : pool_allocator<T{
my_pool_allocator() : pool_allocator<T>() {}
my_pool_allocator(my_pool_allocator<Tconst&) : pool_allocator<T>()
{}
my_pool_allocator(pool_allocator<Tconst&) {}

template <class U>
struct rebind {
typedef my_pool_allocator<Uother;
};

static bool release_memory()
{
return singleton_pool
< pool_allocator_tag
, sizeof(T)
>::release_memory();
}

};

int main(int argc, char* argv[])
{
typedef list<int, my_pool_allocator<int mylist;
mylist IntList;
cout << typeid(IntList.get_allocator()).name() << endl;
return 0;

}

produces the result:
struct my_pool_allocator<int>
and it really does not reclaim memory as I walk into the function
yes, I tried it too. VC8 list actually doesn't use
my_pool_allocator<int>
instance at all.
I don't konw the my_pool_allocator extension is right or not, but I
think it does not affect the result

So, if the container is not vector, it's hard to use
boost::pool_allocator and release_memory, if not hopeless
I agree, even worse, pool allocation is unsuitable
for continuous storage requirements.

according to the standard [23.8] all container's memory
allocation have to come from an instance of allocator
whose value type is the same as the container's value type.
not possible for most containers.

just looking at std::allocator,

template<class _Other>
allocator(const allocator<_Other>&)
{ // construct from a related allocator (do nothing)
}

hints how broken the design is

if the container is using my_pool_allocator rebind
for any additional allocators you could put
release_memory() into my_pool_allocator destructor.
Thanks
regards

DS

Jul 10 '07 #4

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

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.