Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: C++ Memory ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 21 of 41 Topic 9525 of 9823
Post > Topic >>

Re: C++ Memory Management Innovation: GC Allocator

by "Chris Thomasson" <cristom@[EMAIL PROTECTED] > Apr 24, 2008 at 01:43 AM

"xu****wei" <xu****weizh@[EMAIL PROTECTED]
> wrote in message
news:9be66f7e-e89e-4a16-b976-7da3f7565e82@[EMAIL PROTECTED]
>
> 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:

void function() {
 GenericAllocator* const pm_alloc = pthread_getspecific(...);
 // Now I can allocate from m_alloc! :^D
}

void thread() {
 GenericAllocator m_alloc;
 pthread_setspecific(..., &m_alloc);
 function();
}


Don't you think that your design could "possibly" benefit from using TLS?
IMVHO, it would increase its flexibility...


> 2. StreamFlow provides global allocation procedures, while ScopeAlloc
> uses non-static allocator instances to allocate memory.

StreamFlow directs global allocation function's directly to the
calling threads heap... Something like:

void* malloc(size_t sz) {
 PerThreadHeap* const _thisheap = pthread_getspecific(...);
 return _thisheap->allocate(sz);
}

void free(void* ptr) {
 PerThreadHeap* const _thisheap = pthread_getspecific(...);
 _thisheap->deallocate(_thisheap);
}

Using global allocation functions does not limit performance in
any way, shape or form.


> 3. ScopeAlloc forbid you to deallocate memory by yourself.

IMVHO, many low-level programs "need" the flexibility to be able
to control exactly when a piece of memory should be returned to
the system.


> GC Allocator doesn't forbid you to create in thread A and free in
> thread B. But it is not recommended. However, GC Allocator forbid you
> to deallocate memory manually. So, if you implement algorithms that
> are related to t (that is, how many time of the algorithm spent is
> unsure.), GC Allocator doesn't fit you directly.

What does the algorihtm look like for remote deallocations? Here is
how I do it in my vZOOM allocator:
______________________________________________________________
-  create a thread-local instance of a user-defined single-threaded
allocator in every thread (e.g., ms heap w/ HEAP_NO_SERIALIZE).


-  allocation requests are forwarded to this thread-local user allocator
directly.


-  if free request goes from thread that allocated block (e.g., the origin
thread), then free request is forwarded to this thread-local user
allocator.


-  if free request goes from another thread, then you ac***ulate this
block
in per-thread stack-based freelist "belonging to the origin thread", using
single atomic CAS.


-  blocks from this freelist is actually reused/freed in batches using
single atomic SWAP when thread allocates/deallocates another block. For
instance, a thread that fails to allocate from its thread-local heap will
do
a SWAP on the freelist and try and fulfill the allocation request from
there.
______________________________________________________________


My algorithm works with basically any single-threaded allocator, AFAICT,
it would even work with your existing code. You would not need to change
anything. In fact, and end-user could plug your code into this algorithm,
and it would just work.


Any thoughts?


[...]


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




 41 Posts in Topic:
[Proposal for ISO C/C++] C++ Memory Management Innovation: GC A
xushiwei <xushiweizh@[  2008-04-21 12:13:18 
Re: [Proposal for ISO C/C++] C++ Memory Management Innovation: G
"Chris Thomasson&quo  2008-04-21 15:39:15 
Re: [Proposal for ISO C/C++] C++ Memory Management Innovation: G
"Chris Thomasson&quo  2008-04-21 16:13:16 
Re: [Proposal for ISO C/C++] C++ Memory Management Innovation: G
Alberto Ganesh Barbati &l  2008-04-21 20:43:17 
Re: C++ Memory Management Innovation: GC Allocator
marlow.andrew@[EMAIL PROT  2008-04-21 20:43:18 
Re: C++ Memory Management Innovation: GC Allocator
Lance Diduck <lancedid  2008-04-21 20:43:17 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-22 00:08:55 
Re: [Proposal for ISO C/C++] C++ Memory Management Innovation: G
"Chris Thomasson&quo  2008-04-22 10:52:14 
Re: C++ Memory Management Innovation: GC Allocator
Lance Diduck <lancedid  2008-04-22 11:17:48 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-22 11:17:25 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-22 11:13:27 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-22 15:19:26 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-22 15:19:18 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-22 15:22:50 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-22 15:43:17 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-22 22:26:21 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-22 22:25:42 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-22 22:32:36 
Re: C++ Memory Management Innovation: GC Allocator
Francis Glassborow <fr  2008-04-23 14:13:19 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-23 14:43:18 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-24 01:43:35 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-25 03:42:49 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-25 10:47:43 
Re: C++ Memory Management Innovation: GC Allocator
"Stephen Howe"   2008-04-25 10:48:18 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-25 10:47:13 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-25 10:45:25 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-25 10:44:50 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-25 16:15:02 
Re: C++ Memory Management Innovation: GC Allocator
Yongwei Wu <wuyongwei@  2008-04-28 15:58:48 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-28 23:26:31 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-28 23:27:55 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-29 17:43:31 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-30 04:13:27 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-30 04:13:33 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-04-30 17:03:54 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-04-30 21:55:29 
Re: C++ Memory Management Innovation: GC Allocator
Michael Kilburn <crusa  2008-05-06 08:22:59 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-05-06 08:20:19 
Re: C++ Memory Management Innovation: GC Allocator
"Chris Thomasson&quo  2008-05-07 00:31:29 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-05-07 11:03:52 
Re: C++ Memory Management Innovation: GC Allocator
xushiwei <xushiweizh@[  2008-05-08 03:28:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:47:19 CDT 2008.