473,769 Members | 6,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is heap management thread-local?

Hi all,
I know the standard doesn't care about threads (wrongly :-)

But in current compilers implementation, is the "list" which holds count
of the occupied and free heap addresses SHARED among various threads or not?

I don't know if I was clear:

Case1: the list which holds count of what is free and what is occupied
is SHARED among all the threads. In this case each
malloc/new/free/delete needs to acquire a mutex.

Case2: list (almost) thread local: no need for mutexes inside the
malloc/new/free/delete implementations , for most calls. So concurrent
access to malloc/new is fast

In this latter case of course there should be some heap address ranges
which are reserved for use by thread1, some are reserved for thread2...
so they don't usually conflict. If some thread fills up its address
range with mallocs, then it has to take a mutex and rearrange the
address ranges dedicated to the various threads so that it can get some
more heap range for the next mallocs...
I need to know the answer to evaluate if for fast
allocations/deallocations it should be wise to use something like an
allocator pool.


Oh another question: are distinct allocator functions for the various
classes automatically generated? It would seem wise to me to divide the
heap (or the section of the heap dedicated to one thread) in address
ranges, and each address range should be used for one class only. In
this way the allocation for various objects of the same type would be
contiguous and the memory would never be fragmented. Of course if one
class finishes its heap range, a reassignment of the heap ranges with
the other objects would have to be made.
TIA
Jul 22 '05 #1
14 5473
John Doe wrote:
Hi all,
I know the standard doesn't care about threads
So you know you're off-topic here.
(wrongly :-)
Depends on the view.
But in current compilers implementation, is the "list" which holds
count of the occupied and free heap addresses SHARED among various
threads or not?
Depends on the implementation, but I guess it is in most
implementations .
I don't know if I was clear:

Case1: the list which holds count of what is free and what is occupied
is SHARED among all the threads. In this case each
malloc/new/free/delete needs to acquire a mutex.
Or use one of the various other synchronization techniques, of which
some are in this case a lot better (more efficient) than mutexes.
Case2: list (almost) thread local: no need for mutexes inside the
malloc/new/free/delete implementations , for most calls. So concurrent
access to malloc/new is fast

In this latter case of course there should be some heap address ranges
which are reserved for use by thread1, some are reserved for
thread2... so they don't usually conflict. If some thread fills up its
address range with mallocs, then it has to take a mutex and rearrange
the address ranges dedicated to the various threads so that it can get
some more heap range for the next mallocs...
How could it rearrange the address space if there is already something
in it?
I need to know the answer to evaluate if for fast
allocations/deallocations it should be wise to use something like an
allocator pool.
There are quite a lot of malloc implemenations out there, and there may
be some that are quite efficient in multithreading environments. Just
google for them.
Oh another question: are distinct allocator functions for the various
classes automatically generated? It would seem wise to me to divide
the heap (or the section of the heap dedicated to one thread) in
address ranges, and each address range should be used for one class
only. In this way the allocation for various objects of the same type
would be contiguous and the memory would never be fragmented. Of
course if one class finishes its heap range, a reassignment of the
heap ranges with the other objects would have to be made.


Again, I wonder how you can reassign memory that is already in use.

Jul 22 '05 #2
>>Hi all,
I know the standard doesn't care about threads

So you know you're off-topic here.

I thought I had posted to comp.lang.c++!
What's the difference with comp.std.c++ then??


How could it rearrange the address space if there is already something
in it?


You reassign the *free* space of course.
If all threads have used up all the address ranges that was assigned to
them, there is no way to malloc another thing!

Suppose you have 3 threads.
You divide all the heap space in 3 address ranges and assign each range
to a thread.

If thread1 uses all of it, and thread 2 and 3 still have mallocated
nothing, then at the next malloc on thread1 it will acquire the mutex
(or whatever it is), reassign globally free space equally among the
three threads (thread1 will own 1/3 + 2/9 of the heap space, not all
contiguous, the other two will own 2/9 each, contiguous), release the
mutex and then malloc.

Of course the delete/free function needs to be a little smarter: if the
thread who deletes is not the same as the thread who has mallocated, it
needs to acquire the mutex and go to the list of the other thread before
releasing the memory, but it would happen only in a minority of cases,
and never when doing malloc/new.
Jul 22 '05 #3
John Doe wrote:
Hi all,
I know the standard doesn't care about threads


So you know you're off-topic here.


I thought I had posted to comp.lang.c++!
What's the difference with comp.std.c++ then??


comp.std.c++ discusses the C++ standard.

comp.lang.c++ discusses the C++ language as defined by the C++ standard.

This is off-topic here. Any meaningful discussion of this topic would
need a context (such as a particular threading implementation) that this
group does not provide.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #4
Rolf Magnus wrote:
John Doe wrote:
Hi all,
I know the standard doesn't care about threads


So you know you're off-topic here.


The faq addresses threading issues. That seems to suggest to me they aren't
off topic here.

--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #5
In article <SI************ ********@speake asy.net>,
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote:
Rolf Magnus wrote:
John Doe wrote:
Hi all,
I know the standard doesn't care about threads


So you know you're off-topic here.


The faq addresses threading issues. That seems to suggest to me they aren't
off topic here.


Additionally the word "thread" is contained in the C++ standard. So I
agree that this is on topic! ;-)

Typically heap memory is treated as global instead of thread local. The
motivation is to allow one thread to delete memory allocated by another
thread.

There is hope that a future C++ standard will address threading issues,
although nothing has been formally proposed yet. Unfettered discussion
of threading and how it relates to C++ could do nothing but help push
that process along.

-Howard
Jul 22 '05 #6
"John Doe" <jo*****@nowher e.com> wrote
Hi all,
I know the standard doesn't care about threads (wrongly :-)
Why do newbies ALWAYS want to second-guess the battalion of experts who sit
on the standard committee? This is getting soooo old.
But in current compilers implementation, is the "list" which holds count
of the occupied and free heap addresses SHARED among various threads or not?
I don't know if I was clear:

Case1: the list which holds count of what is free and what is occupied
is SHARED among all the threads. In this case each
malloc/new/free/delete needs to acquire a mutex.

Case2: list (almost) thread local: no need for mutexes inside the
malloc/new/free/delete implementations , for most calls. So concurrent
access to malloc/new is fast

In this latter case of course there should be some heap address ranges
which are reserved for use by thread1, some are reserved for thread2...
so they don't usually conflict. If some thread fills up its address
range with mallocs, then it has to take a mutex and rearrange the
address ranges dedicated to the various threads so that it can get some
more heap range for the next mallocs...
I need to know the answer to evaluate if for fast
allocations/deallocations it should be wise to use something like an
allocator pool.


Oh another question: are distinct allocator functions for the various
classes automatically generated? It would seem wise to me to divide the
heap (or the section of the heap dedicated to one thread) in address
ranges, and each address range should be used for one class only. In
this way the allocation for various objects of the same type would be
contiguous and the memory would never be fragmented. Of course if one
class finishes its heap range, a reassignment of the heap ranges with
the other objects would have to be made.


See http://www.cs.umass.edu/~emery/hoard/ for answers to most of your
questions.

Claudio Puviani
Jul 22 '05 #7
"Howard Hinnant" <hi*****@metrow erks.com> wrote in message
news:hi******** *************** ****@syrcnyrdrs-01-ge0.nyroc.rr.co m...
In article <SI************ ********@speake asy.net>,
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote:
Rolf Magnus wrote:
John Doe wrote:

> Hi all,
> I know the standard doesn't care about threads

So you know you're off-topic here.


The faq addresses threading issues. That seems to suggest to me they aren't off topic here.


Additionally the word "thread" is contained in the C++ standard. So I
agree that this is on topic! ;-)


The word 'thread' appears exactly once in the standard
(15.1/2). It's used in the context of exceptions.
Nothing to do with multithreading.

-Mike
Jul 22 '05 #8
In article <UP************ ******@newsread 1.news.pas.eart hlink.net>,
"Mike Wahler" <mk******@mkwah ler.net> wrote:
"Howard Hinnant" <hi*****@metrow erks.com> wrote in message
news:hi******** *************** ****@syrcnyrdrs-01-ge0.nyroc.rr.co m...
In article <SI************ ********@speake asy.net>,
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote:
Rolf Magnus wrote:

> John Doe wrote:
>
>> Hi all,
>> I know the standard doesn't care about threads
>
> So you know you're off-topic here.

The faq addresses threading issues. That seems to suggest to me they aren't off topic here.


Additionally the word "thread" is contained in the C++ standard. So I
agree that this is on topic! ;-)


The word 'thread' appears exactly once in the standard
(15.1/2). It's used in the context of exceptions.
Nothing to do with multithreading.


You looked it up! :-) Thanks, I knew somebody would. Perhaps my humor
is now more clear? <sigh> Perhaps not.

<speaking to this community, not just to Mike - who merely relayed a
fact:>

So, is it your opinion that threading as it relates to C++ is off topic
for comp.lang.c++?

Would it be on topic if a threading library had been accepted by the C++
standards committee into the TR1 Library report? What if it had been
proposed, but not accepted? What if people were just thinking about
proposing such a library? Or must topics (such as threading) be
officially voted in, and ratified by the ISO process before they can be
discussed on comp.lang.c++?

Before one answers, it is perhaps instructive to search
comp.lang.c++.m oderated for discussions on this topic. Should the topic
policy on comp.lang.c++ be substantially different than the topic policy
on comp.lang.c++.m oderated? If your answer is yes, perhaps you can be
partially credited with motivating the creation of
comp.lang.c++.m oderated in the first place.

-Howard
Jul 22 '05 #9
Howard Hinnant wrote:
In article <UP************ ******@newsread 1.news.pas.eart hlink.net>,
"Mike Wahler" <mk******@mkwah ler.net> wrote:
"Howard Hinnant" <hi*****@metrow erks.com> wrote in message
news:hi******** *************** ****@syrcnyrdrs-01-ge0.nyroc.rr.co m...
> In article <SI************ ********@speake asy.net>,
> "Steven T. Hatton" <su******@setid ava.kushan.aa> wrote:
>
> > Rolf Magnus wrote:
> >
> > > John Doe wrote:
> > >
> > >> Hi all,
> > >> I know the standard doesn't care about threads
> > >
> > > So you know you're off-topic here.
> >
> > The faq addresses threading issues. That seems to suggest to me they

aren't
> > off topic here.
>
> Additionally the word "thread" is contained in the C++ standard. So I
> agree that this is on topic! ;-)


The word 'thread' appears exactly once in the standard
(15.1/2). It's used in the context of exceptions.
Nothing to do with multithreading.


You looked it up! :-) Thanks, I knew somebody would. Perhaps my humor
is now more clear? <sigh> Perhaps not.

<speaking to this community, not just to Mike - who merely relayed a
fact:>

So, is it your opinion that threading as it relates to C++ is off topic
for comp.lang.c++?

Would it be on topic if a threading library had been accepted by the C++
standards committee into the TR1 Library report? What if it had been
proposed, but not accepted? What if people were just thinking about
proposing such a library? Or must topics (such as threading) be
officially voted in, and ratified by the ISO process before they can be
discussed on comp.lang.c++?

Before one answers, it is perhaps instructive to search
comp.lang.c++.m oderated for discussions on this topic. Should the topic
policy on comp.lang.c++ be substantially different than the topic policy
on comp.lang.c++.m oderated? If your answer is yes, perhaps you can be
partially credited with motivating the creation of
comp.lang.c++.m oderated in the first place.

-Howard


1) Asking what is on topic is off topic. It's not covered in the Standard.
2) Telling people something is off topic is off topic. It's not covered in
the Standard.
3) Asking where to find the Standad is off topic. It's not covered in the
Standard.
4) You are not obligated to consider off topic discussion as relevent to
your choice as to what should be posted here.

Consult the FAQ, and follow your conscience. There /is/ a lot of stuff in
the FAQ, it's worth getting familiar with. If you're not.
http://www.parashift.com/c++-faq-lite/

BTW, what is a thread of control?
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #10

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

Similar topics

14
30099
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not part of the standard, then just disregard this question. Here's some questions I'm confused about, and if you can add anything else, please do so! Is the stack limited for each program?
17
5048
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
6
2290
by: Victor Nazarov | last post by:
So seems to be slightly wrong group, but... The question is: Is there any extentions for C or well known libraries to implement heap managment, for example if I want to allocate a randome data in the static array of chars? For example: Heap *heap_new (void *ptr, size_t size/*, may be some other arguments*/); void heap_delete (Heap *heapp); void *heap_alloc (Heap *heapp, size_t object_size);
7
1749
by: Michael Cornelison | last post by:
I believe I have found a serious performance problem with heap management in C++ .Net. I have an application does the following thousands of times: vint = new int; vchar = new char; The performance of these vector creations varies by a factor of 40 or more. It is also sensitive to the
3
1972
by: Aravindakumar Venugopalan | last post by:
Hi , A Windows form application which interacting with the unmanaged C++ codes . In unmanaged c++ code we allocate around 130MB on the heap for annalysing high resolution images . Earlier during the processing ee do lot of process on the image and the memory reaches high at one point of time to 1.2GB , after that we clear all the memory being used so the memory in the task manager comes to really low. Also I am calling CompactHeap...
2
1753
by: Ben R. | last post by:
I recently read that the heap that you access when you use malloc and free is created by MSVCRT. Is the "default" or process heap ever used then if you're not explicitly calling heapalloc with that heap? Why does MSVCRT not just use this default process heap?
37
2785
by: yogpjosh | last post by:
Hello All, I was asked a question in an interview.. Its related to dynamically allocated and deallocated memory. eg. //start char * p = new char; ...
24
2896
by: arcticool | last post by:
I had an interview today and I got destroyed :( The question was why have a stack and a heap? I could answer all the practical stuff like value types live on the stack, enums are on the stack, as are structs, where classes are on the heap... when value types go out of scope the memory is re- allocated, object remain in memory waiting to be cleaned up by the garbage collector, etc, but he responded 'so why not just put say a class on the...
1
3614
by: Chris Mullins | last post by:
We've been using the SSLStream class found in System.Net.Security to build a giant Sockets server that provides TLS encryption at the channel leve. Before .Net 2.0, we used an open-source encryption channel from Mentalis, and have even looked at the Mono implementation for doing this. The problem comes from the SSLStream not doing any buffer management. None. Zero. In the "no buffer management" case, each SSLStream allocates bufferes...
11
5216
by: Andy Watson | last post by:
I have an application that scans and processes a bunch of text files. The content I'm pulling out and holding in memory is at least 200MB. I'd love to be able to tell the CPython virtual machine that I need a heap of, say 300MB up front rather than have it grow as needed. I've had a scan through the archives of comp.lang.python and the python docs but cannot find a way to do this. Is this possible to configure the PVM this way? ...
0
9587
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
9423
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
10211
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
9993
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,...
1
7406
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
6672
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
5298
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...
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.