Memory Allocation

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 29 16:26:04 PDT 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:
> > On Wednesday, 29 March 2017 at 19:19:48 UTC, Enigma wrote:
> > > [...]
> > 
> > It looks like you are looking for this:
> > http://dlang.org/phobos-prerelease/std_experimental_allocator_building_blocks_region.html.
> 
> 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.

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. -- YHL


More information about the Digitalmars-d-learn mailing list