How to check a struct exists at a particular memory address?
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 18 17:25:23 PDT 2017
On Thursday, 18 May 2017 at 20:20:47 UTC, Gary Willoughby wrote:
> This might be a really silly question but:
>
> I've allocated some memory like this (Foo is a struct):
>
> this._data = cast(Foo*) calloc(n, Foo.sizeof);
>
> How can I then later check that there is a valid Foo at
> `this._data` or `this._data + n`?
The normal way to do this is to have an int (or whatever, larger
size means less likely to fall fowl on random data) that is
initialised to a known "random" value. See the ELF magic headers
for example.
More information about the Digitalmars-d-learn
mailing list