testing if data is allocated on the stack or heap
flamencofantasy
flamencofantasy at gmail.com
Wed Oct 18 06:33:26 UTC 2017
On Tuesday, 17 October 2017 at 23:59:19 UTC, Steven Schveighoffer
wrote:
> On 10/17/17 7:32 PM, flamencofantasy wrote:
>> On Tuesday, 17 October 2017 at 17:27:17 UTC, Biotronic wrote:
>>> On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote:
>>>> [...]
>>>
>>> I have very little knowledge about sbrk, so here's my
>>> solution.
>>>
>>> Tested on win32 and win64.
>>>
>>> [...]
>>
>> Try this;
>>
>> unittest {
>> int[5*1024] n;
>> int* p = new int;
>>
>> assert(n.onStack);
>> assert(!p.onStack);
>> }
>
> The second is wrong. You are asserting that the storage of p is
> not on the stack, but it is.
>
> What p *points at* is not on the stack.
>
> So the correct call should be:
>
> assert(!(*p).onStack);
>
> or (IMO) less ugly: assert(!onStack(*p));
>
> -Steve
you misunderstood, the code is from biotronic's post, i just made
a static array of 5kb to point out how it fails, in just one way
out of a dozen other possibilities.
More information about the Digitalmars-d-learn
mailing list