[Proposal for ISO C/C++] C++ Memory Management Innovation: GC Allocator
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c++.moderated Profile…
 Up
Re: C++ Memory Management Innovation: GC Allocator         


Author: Chris Thomasson
Date: Apr 23, 2008 23:50

"xushiwei" gmail.com> wrote in message
news:9be66f7e-e89e-4a16-b976-7da3f7565e82@y38g2000hsy.googlegroups.com...
[...]
>
> The difference between StreamFlow and ScopeAlloc (or AutoFreeAlloc)
> are:
>
> 1. StreamFlow uses thread local storage, while ScopeAlloc doesn't.

There are benefits for using TLS. Think of a simple contrived scenario like:

void function() {
// I need to allocate from m_alloc...
// How can I do this without adding any parameters?
}

void thread() {
GenericAllocator m_alloc;
function();
}

AFAICT, your allocator can use TLS as-is... Basically, something like:
Show full article (3.56Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: Chris Thomasson
Date: Apr 25, 2008 01:50

"xushiwei" gmail.com> wrote in message
news:56aee384-8f2e-40ac-8b6f-54fcd808215f@q27g2000prf.googlegroups.com...
>{ Please do not quote extraneous material, such as the clc++m banner.
> Please also note that top posting is discouraged in this group. -mod }
>
> Yes, GC Allocator is not thread-safe. It's my EMPHASES in
> implementation section. And that is
> why GC Allocator is so fast.
>
> I don't think implementing a producer/consumer pattern is a common
> case. So, why not implement an allocator without a multithreaded lock,
> then use it with a explicit lock when you implement a producer/
> consumer pattern (or something that need to share memory)?

[...]

Well, I use producer/consumer all the time. AFAICT, it is a fairly common
pattern indeed.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: xushiwei
Date: Apr 25, 2008 08:51

Hello all,

I add a new class: TlsBlockPool. And now you can define a ScopeAlloc
instance without given parameters:

ScopeAlloc alloc;

It is same as:

ScopeAlloc alloc(TlsBlockPool::instance());

Thank Chris Thomasson for his suggestion.

---

class TlsBlockPool
{
public:
TlsBlockPool() { init(); }
~TlsBlockPool() { term(); }

static void init();
static void term();

static BlockPool& instance();
};
Show full article (0.90Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: Stephen Howe
Date: Apr 25, 2008 08:51

> I don't think implementing a producer/consumer pattern is a common
> case.

Of course it is.
Common producer/consumer patterns are stacks, queues or priority queues -
all in the standard library
Having one or more threads adding elements and one or more different threads
removing elements (thread safe of course) seems normal.

Stephen Howe

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: xushiwei
Date: Apr 25, 2008 08:51

On Apr 25, 5:42 pm, "Chris Thomasson" comcast.net> wrote:
>
> Well, I use producer/consumer all the time. AFAICT, it is a fairly common
> pattern indeed.
>

Yes, and it is same to me. But you only need to implement ONE producer/
consumer pattern, don't you?

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: xushiwei
Date: Apr 25, 2008 08:51

On Apr 24, 3:43 pm, "Chris Thomasson" comcast.net> wrote:
>
> There are benefits for using TLS. Think of a simple contrived scenario like:
>
> void function() {
> // I need to allocate from m_alloc...
> // How can I do this without adding any parameters?
>
> }
>
> void thread() {
> GenericAllocator m_alloc;
> function();
>
> }
>
> AFAICT, your allocator can use TLS as-is... Basically, something like:
>
> void function() {
> GenericAllocator* const pm_alloc = pthread_getspecific(...); ...
Show full article (3.56Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: xushiwei
Date: Apr 25, 2008 08:52

On Apr 24, 3:43 pm, "Chris Thomasson" comcast.net> wrote:
>
> There are benefits for using TLS. Think of a simple contrived scenario like:
>
> void function() {
> // I need to allocate from m_alloc...
> // How can I do this without adding any parameters?
>
> }
>
> void thread() {
> GenericAllocator m_alloc;
> function();
>
> }
>
> AFAICT, your allocator can use TLS as-is... Basically, something like:
>
> void function() {
> GenericAllocator* const pm_alloc = pthread_getspecific(...); ...
Show full article (1.36Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: Chris Thomasson
Date: Apr 25, 2008 14:27

"xushiwei" gmail.com> wrote in message
news:a92bf2cd-5cda-45d6-a637-f799e63694da@q1g2000prf.googlegroups.com...
> On Apr 24, 3:43 pm, "Chris Thomasson" comcast.net> wrote:
>>
>> There are benefits for using TLS. Think of a simple contrived scenario
>> like:
>>
>> void function() {
>> // I need to allocate from m_alloc...
>> // How can I do this without adding any parameters?
>>
>> }
>>
>> void thread() {
>> GenericAllocator m_alloc;
>> function();
>>
>> }
>>
>> AFAICT, your allocator can use TLS as-is... Basically, something like: ...
Show full article (1.29Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: Yongwei Wu
Date: Apr 28, 2008 14:00

On Apr 23, 5:22 am, xushiwei gmail.com> wrote:
> In fact, "GC Allocator" is NOT "GC".
>
> "GC Allocator" focus:
>
> 1. It is a better "Smart Pointer".
> 2. Deleting objects manually is no need if you use "GC Allocator".

I found it difficult to justify your statement. How do you deallocate
objects, really? You did not explain well in the PDF, and a glance at
the code indicated that you simply do *not* deallocate objects in the
middle of a function. If I did not read wrong, your work is not
suitable in most real-world cases that require a program to run for
more than a short while.
> 3. Use non-static allocator instances to allocate memory instead of
> global new/delete procedures. Then multithreads locks are OPTIONAL and
> you can use explicit locks if you need.
>
> You can consider "GC Allocator" as a "Smart Pointer" or a "Allocator",
> but It isn't a "GC".
Show full article (1.15Kb)
no comments
Re: C++ Memory Management Innovation: GC Allocator         


Author: xushiwei
Date: Apr 28, 2008 21:30

{ Please note that top-posting is discouraged in this group. -mod }

I'm glad to say that now "GC Allocator" is a sandbox library of boost.

To gain the source code, please svn checkout http://svn.boost.org/svn/boost/sandbox/memory/.

Examples:

* simple_examples.cpp (http://svn.boost.org/svn/boost/sandbox/
memory/libs/memory/test/memory/simple_examples.cpp)
* stl_containers.cpp (http://svn.boost.org/svn/boost/sandbox/
memory/libs/memory/test/memory/stl_containers.cpp)

On 4月26日, 上午6时15分, "Chris Thomasson" comcast.net> wrote:
>
> Great! IMVHO, it will only make your hard work much more flexible indeed.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
 
1 2 3 4 5