www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Will the GC scan this pointer?

reply Lass Safin <lasssafin gmail.com> writes:
// Omitting the required imports.

void[] ptr;

void main() {
     uint buffer;
     glCreateBuffers(1, &buffer);
     // Filling the buffer with data and such...
     ptr = glMapNamedBufferRange(buffer, 0, 512, GL_MAP_WRITE_BIT 
| GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT)[0 .. 512];
}

So the question is: Will the GC scan ptr? As you can see, it is a 
write-only pointer, so reading from it will cause undefined 
behavior (such as return data which looks like a pointer to 
data..), and can potentially be reallly slow.

Do I have to mark it with NO_SCAN each time I call 
glMapNamedBufferRange?
Apr 24 2016
next sibling parent ag0aep6g <anonymous example.com> writes:
On 24.04.2016 13:03, Lass Safin wrote:
 // Omitting the required imports.

 void[] ptr;

 void main() {
      uint buffer;
      glCreateBuffers(1, &buffer);
      // Filling the buffer with data and such...
      ptr = glMapNamedBufferRange(buffer, 0, 512, GL_MAP_WRITE_BIT |
 GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT)[0 .. 512];
 }

 So the question is: Will the GC scan ptr?
[...]
 Do I have to mark it with NO_SCAN each time I call glMapNamedBufferRange?
I don't think so. The GC generally doesn't care about heap memory that's not been allocated through it. As I understand it, you'd have to state explicitly that that memory should be scanned.
Apr 24 2016
prev sibling parent safety0ff <safety0ff.dev gmail.com> writes:
On Sunday, 24 April 2016 at 11:03:11 UTC, Lass Safin wrote:
 So the question is: Will the GC scan ptr? As you can see, it is 
 a write-only pointer, so reading from it will cause undefined 
 behavior (such as return data which looks like a pointer to 
 data..), and can potentially be reallly slow.
The GC will see that ptr doesn't point to memory managed by the GC and move on.
 Do I have to mark it with NO_SCAN each time I call 
 glMapNamedBufferRange?
No, calling setAttr on memory not managed by the GC will do nothing.
Apr 24 2016