View source code
Display the source code in std/experimental/allocator/building_blocks/ascending_page_allocator.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Struct std.experimental.allocator.building_blocks.ascending_page_allocator.SharedAscendingPageAllocator
SharedAscendingPageAllocator
is the threadsafe version of AscendingPageAllocator
.
struct SharedAscendingPageAllocator
;
Constructors
Name | Description |
---|---|
this
(n)
|
Rounds the mapping size to the next multiple of the page size and calls
the OS primitive responsible for creating memory mappings: mmap on POSIX and
VirtualAlloc on Windows.
|
Methods
Name | Description |
---|---|
alignedAllocate
(n, a)
|
Rounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the memory. |
allocate
(n)
|
Rounds the allocation size to the next multiple of the page size. The allocation only reserves a range of virtual pages but the actual physical memory is allocated on demand, when accessing the memory. |
deallocate
(b)
|
Decommit all physical memory associated with the buffer given as parameter, but keep the range of virtual addresses. |
deallocateAll
()
|
Removes the memory mapping causing all physical memory to be decommited and the virtual address space to be reclaimed. |
expand
(b, delta)
|
If the passed buffer is not the last allocation, then delta can be
at most the number of bytes left on the last page.
Otherwise, we can expand the last allocation until the end of the virtual
address range.
|
getAvailableSize
()
|
Returns the available size for further allocations in bytes. |
goodAllocSize
(n)
|
Rounds the requested size to the next multiple of the page size. |
owns
(buf)
|
Returns Ternary if the passed buffer is inside the range of virtual adresses.
Does not guarantee that the passed buffer is still valid.
|
Example
import core .memory : pageSize;
import core .thread : ThreadGroup;
enum numThreads = 100;
shared SharedAscendingPageAllocator a = SharedAscendingPageAllocator(pageSize * numThreads);
void fun()
{
void[] b = a .allocate(pageSize);
writeln(b .length); // pageSize
assert(a .deallocate(b));
}
auto tg = new ThreadGroup;
foreach (i; 0 .. numThreads)
{
tg .create(&fun);
}
tg .joinAll();
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.