digitalmars.D.learn - Memory Allocation
- Enigma (23/23) Mar 29 2017 I have a memory buffer allocated using different methods. It is
- Faux Amis (2/4) Mar 29 2017 Can you maybe just tread it like an array and slice it for allocation?
- Faux Amis (2/7) Mar 29 2017 *treat*
- Petar Kirov [ZombineDev] (3/26) Mar 29 2017 It looks like you are looking for this:
- Enigma (5/9) Mar 29 2017 But these seem to require passing a mallocator. I simply want to
- H. S. Teoh via Digitalmars-d-learn (11/21) Mar 29 2017 Huh? Where does it say that a mallocator is required?
- Enigma (3/21) Mar 30 2017 Thanks. All the examples show using a size rather than an array
- Gary Willoughby (3/8) Mar 30 2017 You can re-task the GC to use an arena if that's suitable:
- Enigma (2/11) Mar 30 2017 cool. thanks.
I have a memory buffer allocated using different methods. It is simply a pointer and a size. I would like to be able to manage this buffer by treating it as a memory pool or heap. I think I can use allocators to do this but not sure how. Effectively I want something like new or malloc but it pulls from the memory buffer rather than the program heap. // Allocated once at program start void* FancyBuffer = FancyAlloc(1000); Then when I want to use the buffer I'll do stuff like auto myptr = FancyMalloc(10); .... FancyFree(myptr); or whatever. The main thing is, I don't want to have to write my own allocator to manage this buffer as it seems that D's allocators would do a better job. I imagine that most of the time the buffer will not have more than one piece of code using it(no overlapping uses) but since I won't be 100% sure, I need allow for the cases where there might be overlapping usage. (else I wouldn't ever have to worry about "allocating or releasing" from it. Thanks.
Mar 29 2017
On 2017-03-29 21:19, Enigma wrote:I have a memory buffer allocated using different methods. It is simply a pointer and a size.Can you maybe just tread it like an array and slice it for allocation?
Mar 29 2017
On 2017-03-29 23:30, Faux Amis wrote:On 2017-03-29 21:19, Enigma wrote:*treat*I have a memory buffer allocated using different methods. It is simply a pointer and a size.Can you maybe just tread it like an array and slice it for allocation?
Mar 29 2017
On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:I have a memory buffer allocated using different methods. It is simply a pointer and a size. I would like to be able to manage this buffer by treating it as a memory pool or heap. I think I can use allocators to do this but not sure how. Effectively I want something like new or malloc but it pulls from the memory buffer rather than the program heap. // Allocated once at program start void* FancyBuffer = FancyAlloc(1000); Then when I want to use the buffer I'll do stuff like auto myptr = FancyMalloc(10); .... FancyFree(myptr); or whatever. The main thing is, I don't want to have to write my own allocator to manage this buffer as it seems that D's allocators would do a better job. I imagine that most of the time the buffer will not have more than one piece of code using it(no overlapping uses) but since I won't be 100% sure, I need allow for the cases where there might be overlapping usage. (else I wouldn't ever have to worry about "allocating or releasing" from it. Thanks.It looks like you are looking for this: http://dlang.org/phobos-prerelease/std_experimental_allocator_building_blocks_region.html.
Mar 29 2017
On Wednesday, 29 March 2017 at 21:36:14 UTC, Petar Kirov [ZombineDev] wrote:On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:But these seem to require passing a mallocator. I simply want to pass an already allocated region/block/buffer and have the allocators use it. I will allocate and free on my own.[...]It looks like you are looking for this: http://dlang.org/phobos-prerelease/std_experimental_allocator_building_blocks_region.html.
Mar 29 2017
On Wed, Mar 29, 2017 at 11:01:12PM +0000, Enigma via Digitalmars-d-learn wrote:On Wednesday, 29 March 2017 at 21:36:14 UTC, Petar Kirov [ZombineDev] wrote:Huh? Where does it say that a mallocator is required? As far as I can tell, you could simply do this: void[] myBuffer = ...; auto allocator = Region!()(myBuffer); auto p = allocator.allocate(...); The default parent allocator is NullAllocator, which does nothing, so that leaves the management of myBuffer entirely up to you. T -- Life would be easier if I had the source code. -- YHLOn Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:But these seem to require passing a mallocator. I simply want to pass an already allocated region/block/buffer and have the allocators use it. I will allocate and free on my own.[...]It looks like you are looking for this: http://dlang.org/phobos-prerelease/std_experimental_allocator_building_blocks_region.html.
Mar 29 2017
On Wednesday, 29 March 2017 at 23:26:04 UTC, H. S. Teoh wrote:On Wed, Mar 29, 2017 at 11:01:12PM +0000, Enigma via Digitalmars-d-learn wrote:Thanks. All the examples show using a size rather than an array so I assumed that was the case.On Wednesday, 29 March 2017 at 21:36:14 UTC, Petar Kirov [ZombineDev] wrote:Huh? Where does it say that a mallocator is required? As far as I can tell, you could simply do this: void[] myBuffer = ...; auto allocator = Region!()(myBuffer); auto p = allocator.allocate(...); The default parent allocator is NullAllocator, which does nothing, so that leaves the management of myBuffer entirely up to you. T[...]But these seem to require passing a mallocator. I simply want to pass an already allocated region/block/buffer and have the allocators use it. I will allocate and free on my own.
Mar 30 2017
On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:I have a memory buffer allocated using different methods. It is simply a pointer and a size. I would like to be able to manage this buffer by treating it as a memory pool or heap. I think I can use allocators to do this but not sure how.You can re-task the GC to use an arena if that's suitable: https://bitbucket.org/infognition/dstuff/src/1dca752af1021ed5998bb041004465674695113f/gcarena.d?fileviewer=file-view-default
Mar 30 2017
On Thursday, 30 March 2017 at 11:22:05 UTC, Gary Willoughby wrote:On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:cool. thanks.I have a memory buffer allocated using different methods. It is simply a pointer and a size. I would like to be able to manage this buffer by treating it as a memory pool or heap. I think I can use allocators to do this but not sure how.You can re-task the GC to use an arena if that's suitable: https://bitbucket.org/infognition/dstuff/src/1dca752af1021ed5998bb041004465674695113f/gcarena.d?fileviewer=file-view-default
Mar 30 2017