www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.container / tightArray / class (de)allocators

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
Hi, since std.container is now part of the DMD compiler and class 
allocators/deallocaters are no longer part of the language, the way to 
go now, as far as I understand now, it to use tightArray.

So, how to use tightArray to allocate structs and classes from a 
specific memory pool? Will such allocations be under GC control or not?

For example: How do I ensure that an allocation is done from a 
memory-mapped file area?

---
Robert M. Münch
http://www.robertmuench.de
Jun 15 2010
parent reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
On 2010-06-15 09:49:29 +0200, Robert M. Münch said:

 Hi, since std.container is now part of the DMD compiler and class 
 allocators/deallocaters are no longer part of the language, the way to 
 go now, as far as I understand now, it to use tightArray.
 
 So, how to use tightArray to allocate structs and classes from a 
 specific memory pool? Will such allocations be under GC control or not?
 
 For example: How do I ensure that an allocation is done from a 
 memory-mapped file area?
Has noone a tipp for me how to make & use an own allocator? --- Robert M. Münch http://www.robertmuench.de
Jun 15 2010
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
Robert M. Münch wrote:
 On 2010-06-15 09:49:29 +0200, Robert M. Münch said:
 
 Hi, since std.container is now part of the DMD compiler and class 
 allocators/deallocaters are no longer part of the language, the way to 
 go now, as far as I understand now, it to use tightArray.

 So, how to use tightArray to allocate structs and classes from a 
 specific memory pool? Will such allocations be under GC control or not?

 For example: How do I ensure that an allocation is done from a 
 memory-mapped file area?
Has noone a tipp for me how to make & use an own allocator?
Sorry for being slow on that. Currently TightArray (renamed to Array) uses hardcoded calls to malloc and free. I'd be glad to use a better design if one came along. Andrei
Jun 15 2010
next sibling parent reply Stephan <spam extrawurst.org> writes:
On 16.06.2010 08:59, Andrei Alexandrescu wrote:
 Robert M. Münch wrote:
 On 2010-06-15 09:49:29 +0200, Robert M. Münch said:

 Hi, since std.container is now part of the DMD compiler and class
 allocators/deallocaters are no longer part of the language, the way
 to go now, as far as I understand now, it to use tightArray.

 So, how to use tightArray to allocate structs and classes from a
 specific memory pool? Will such allocations be under GC control or not?

 For example: How do I ensure that an allocation is done from a
 memory-mapped file area?
Has noone a tipp for me how to make & use an own allocator?
Sorry for being slow on that. Currently TightArray (renamed to Array) uses hardcoded calls to malloc and free. I'd be glad to use a better design if one came along. Andrei
Btw. I downloaded the new dmd(2047) and tried to use this new Array template. But it does not seem to work: import std.container; void main() { Array!(int) a; } //src\phobos\std\container.d(1660): Error: function core.stdc.stdlib.free (void* ptr) is not callable using argument types (int[]) //src\phobos\std\container.d(1660): Error: cannot implicitly convert expression ((*this._data)._payload) of type int[] to void* is it my fault? does anyone else have this problem?
Jun 16 2010
parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Wed, 16 Jun 2010 10:04:05 +0200, Stephan wrote:
 Btw. I downloaded the new dmd(2047) and tried to use this new Array
 template. But it does not seem to work:
 
 import std.container;
 
 void main()
 {
 	Array!(int) a;
 }
 
 //src\phobos\std\container.d(1660): Error: function
 core.stdc.stdlib.free (void* ptr) is not callable using argument types
 (int[])
 //src\phobos\std\container.d(1660): Error: cannot implicitly convert
 expression ((*this._data)._payload) of type int[] to void*
 
 
 is it my fault? does anyone else have this problem?
It's a bug (and a strange one at that). I've checked in a fix, see: http://d.puremagic.com/issues/show_bug.cgi?id=4327 -Lars
Jun 16 2010
parent Stephan <spam extrawurst.org> writes:
On 16.06.2010 11:39, Lars T. Kyllingstad wrote:
 On Wed, 16 Jun 2010 10:04:05 +0200, Stephan wrote:
 Btw. I downloaded the new dmd(2047) and tried to use this new Array
 template. But it does not seem to work:

 import std.container;

 void main()
 {
 	Array!(int) a;
 }

 //src\phobos\std\container.d(1660): Error: function
 core.stdc.stdlib.free (void* ptr) is not callable using argument types
 (int[])
 //src\phobos\std\container.d(1660): Error: cannot implicitly convert
 expression ((*this._data)._payload) of type int[] to void*


 is it my fault? does anyone else have this problem?
It's a bug (and a strange one at that). I've checked in a fix, see: http://d.puremagic.com/issues/show_bug.cgi?id=4327 -Lars
thanks for that, i hope its in the next release.
Jun 16 2010
prev sibling parent reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
On 2010-06-16 08:59:47 +0200, Andrei Alexandrescu said:

 Sorry for being slow on that. Currently TightArray (renamed to Array) 
 uses hardcoded calls to malloc and free. I'd be glad to use a better 
 design if one came along.
Hi Andrei, ok. At least it's a chart. I'm going to take a look and first try to replace malloc/free with my versions and than we can see how to make these functions replace-able at compile/run-time. --- Robert M. Münch http://www.robertmuench.de
Jun 16 2010
parent reply BLS <windevguy hotmail.de> writes:
On 16/06/2010 10:50, Robert M. Münch wrote:
 On 2010-06-16 08:59:47 +0200, Andrei Alexandrescu said:

 Sorry for being slow on that. Currently TightArray (renamed to Array)
 uses hardcoded calls to malloc and free. I'd be glad to use a better
 design if one came along.
Hi Andrei, ok. At least it's a chart. I'm going to take a look and first try to replace malloc/free with my versions and than we can see how to make these functions replace-able at compile/run-time. --- Robert M. Münch http://www.robertmuench.de
HM'''' How to bring a (Tight)Array designed as memory watch dog and a fixed sized, but chunked, memory mapped file together. I am curious .. (to say the least)
Jun 16 2010
parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> writes:
On 2010-06-16 15:33:40 +0200, BLS said:

 How to bring a (Tight)Array designed as memory watch dog and a fixed 
 sized, but chunked, memory mapped file together.
 I am curious .. (to say the least)
The idea is quite simple (not so much dependend on Array): - implement a memory-allocator and manager that manages the free space in a memory mapped file (MMF) - implement a based pointer type to have address independent pointers inside the MMF - provide a way to allocate data-structures using based pointers via this memory manager in the memory mapped file - use these data-structures at run-time The run-time objects will be persistent by default. The based pointer ensures that links between such objects are pesistent. The memory manager keeps track of the free areas and used areas of the MMF much like a file-system. As I don't want to mirror all D runtime stuff I'm seeking for a way to gently exchange/swap the normal GC memory allocator through a MMF allocator, without impacting the normal types, classes etc. -- Robert M. Münch http://www.robertmuench.de
Jun 16 2010