Request help on allocator.

ryuukk_ ryuukk.dev at gmail.com
Sat Dec 2 19:30:18 UTC 2023


On Saturday, 2 December 2023 at 19:13:18 UTC, Vino B wrote:
> Hi All,
>
>   Request your help in understanding the below program, with 
> the below program I can allocate 8589934592(8GB) it prints the 
> length 8589934592(8GB) where as my laptop has only 4 GB so the 
> confusion is that how can this program allocate 8GB RAM when I 
> have only 4GB of RAM installed
>
>
> ```
> import std.algorithm.comparison : max;
> import 
> std.experimental.allocator.building_blocks.allocator_list : 
> AllocatorList;
> import std.experimental.allocator.building_blocks.bucketizer;
> import std.experimental.allocator.building_blocks.free_list : 
> FreeList;
> import std.experimental.allocator.building_blocks.region : 
> Region;
> import std.experimental.allocator.building_blocks.segregator;
> import std.experimental.allocator.common : unbounded;
> import std.experimental.allocator.mallocator : Mallocator;
> import std.stdio: writeln;
>
> void main () {
> alias FList = FreeList!(Mallocator, 0, unbounded);
> alias A = Segregator!(
>       8, FreeList!(Mallocator, 0, 8),
>       128, Bucketizer!(FList, 1, 128, 16),
>       256, Bucketizer!(FList, 129, 256, 32),
>       512, Bucketizer!(FList, 257, 512, 64),
>       1024, Bucketizer!(FList, 513, 1024, 128),
>       2048, Bucketizer!(FList, 1025, 2048, 256),
>       3584, Bucketizer!(FList, 2049, 3584, 512),
>       4097 * 1024, AllocatorList!(n => Region!Mallocator(max(n, 
> 1024 * 4096))),
>       Mallocator
> );
> A tuMalloc;
> auto c = tuMalloc.allocate(8589934592);  // 8GB
> writeln(c.length);                       // output: 8589934592
> tuMalloc.deallocate(c);
> }
> ```
>
> From,
> Vino

This is normal behavior on linux, it's called overcommit memory, 
i think it was meant to allow things like fork() to work properly

https://stackoverflow.com/a/7504354


More information about the Digitalmars-d-learn mailing list