digitalmars.D.learn - Pointer to std.container.Array data for C library
- Oleg (5/5) Aug 28 2015 Hello!
- John Colvin (3/8) Aug 28 2015 I'm pretty sure you can just take the address of the first
- Oleg (5/13) Aug 28 2015 I've tried, it throws
- John Colvin (3/16) Aug 28 2015 That's unexpected. Could you provide a full example that does
Hello! Is it possible to get pointer to a data in std.container.Array like .ptr from an array? I need to pass a pointer to some C function (from DerelictGL3 binding) and avoid GC allocation. Thank you!
Aug 28 2015
On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:Hello! Is it possible to get pointer to a data in std.container.Array like .ptr from an array? I need to pass a pointer to some C function (from DerelictGL3 binding) and avoid GC allocation. Thank you!I'm pretty sure you can just take the address of the first element, e.g. &a[0] or &a.front
Aug 28 2015
On Friday, 28 August 2015 at 18:21:04 UTC, John Colvin wrote:On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:I've tried, it throws core.exception.RangeError /usr/include/dmd/phobos/std/container/array.d(571): Range violation If I make an array from the Array container with foreach ad pass it's .ptr - it worksHello! Is it possible to get pointer to a data in std.container.Array like .ptr from an array? I need to pass a pointer to some C function (from DerelictGL3 binding) and avoid GC allocation. Thank you!I'm pretty sure you can just take the address of the first element, e.g. &a[0] or &a.front
Aug 28 2015
On Friday, 28 August 2015 at 18:31:00 UTC, Oleg wrote:On Friday, 28 August 2015 at 18:21:04 UTC, John Colvin wrote:That's unexpected. Could you provide a full example that does this?On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:I've tried, it throws core.exception.RangeError /usr/include/dmd/phobos/std/container/array.d(571): Range violationHello! Is it possible to get pointer to a data in std.container.Array like .ptr from an array? I need to pass a pointer to some C function (from DerelictGL3 binding) and avoid GC allocation. Thank you!I'm pretty sure you can just take the address of the first element, e.g. &a[0] or &a.front
Aug 28 2015
On Friday, 28 August 2015 at 18:40:33 UTC, John Colvin wrote:On Friday, 28 August 2015 at 18:31:00 UTC, Oleg wrote:I found solution. I call length instead of reserve. It calls ensureInitialized and everything works fine. By default, Array won't initialize store.On Friday, 28 August 2015 at 18:21:04 UTC, John Colvin wrote:That's unexpected. Could you provide a full example that does this?On Friday, 28 August 2015 at 17:45:21 UTC, Oleg wrote:I've tried, it throws core.exception.RangeError /usr/include/dmd/phobos/std/container/array.d(571): Range violationHello! Is it possible to get pointer to a data in std.container.Array like .ptr from an array? I need to pass a pointer to some C function (from DerelictGL3 binding) and avoid GC allocation. Thank you!I'm pretty sure you can just take the address of the first element, e.g. &a[0] or &a.front
Aug 28 2015
On Friday, 28 August 2015 at 18:46:23 UTC, Oleg wrote:I found solution. I call length instead of reserve. It calls ensureInitialized and everything works fine. By default, Array won't initialize store.Oh, reserve calls it too. My mistake. I found the problem, that's because I passed an empty Array (like Array!int.init).
Aug 28 2015