Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?
    rempas 
    rempas at tutanota.com
       
    Mon Apr  4 07:48:40 UTC 2022
    
    
  
On Monday, 4 April 2022 at 07:39:08 UTC, Salih Dincer wrote:
> On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote:
>>
>> Does anyone knows what's going on here?
>
> Source code?
Why does it matter?
```
import core.memory;
import core.stdc.stdio;
import core.stdc.stdlib;
extern (C) void main() {
   char* str = cast(char*)pureMalloc(23);
   str[0] = 'J';
   str[1] = 'o';
   str[2] = 'h';
   str[3] = 'n';
   printf("My name is: %s\n", str);
   exit(0);
}
```
Maybe, I didn't explained it properly. The example works. 
However, I wonder if it randomly works or if it is safe to do 
something like that as if the bytes have been initialized to '\0'.
    
    
More information about the Digitalmars-d-learn
mailing list