xxxxxxxxxx
import std.stdio, std.container.array, core.memory;
extern(C) void* sbrk(long);
void main(string[] args)
{
auto start_sbrk = sbrk(0);
writeln("start sbrk: ", start_sbrk);
size_t length;
int[] arr;
arr ~= 1;
writeln("arr.ptr:\t", arr.ptr);
auto arr1 = arr.dup;
writeln("arr1.ptr:\t", arr1.ptr);
auto addr_of_length = &length;
writeln("lenaddr:\t", addr_of_length);
void heapOrStack(void* ptr)
{
if (ptr > start_sbrk)
write(" stack");
else
write(" heap");
}
write("lenaddr:\t");
heapOrStack(cast(void*)addr_of_length);
writeln;
write("arr.ptr:\t");
heapOrStack(cast(void*)arr.ptr);
writeln;
write("arr1.ptr:\t");
heapOrStack(cast(void*)arr1.ptr);
writeln;
}