#Copy an Element out of Allocated Memory

1 messages · Page 1 of 1 (latest)

safe juniper
#

Hello!
I am wondering if there is an easy way to copy an element out of an Allocated section of memory back to the stack.

Example:

const count = try getPhysicalDeviceCount();

var devices = try allocator.alloc(c.VkPhysicalDevice, count);
defer allocator.free(devices)

// ignoring the result in this sample
c.vkEnumeratePhysicalDevices(instance, &count, devices.ptr);

var device: c.VkPhysicalDevice = undefined;
// @copy doesn't exist... but it is the magic I am missing
@copy(&device, &devices[0]);
return device;

Does @copy() exist but I have missed it? Can I create something similar?

proud flame
safe juniper
#

I believe that I got a segfault due to the defer allocator.free(devices)

proud flame
#

sounds like a different issue

#

Could you send the stack trace?

safe juniper
#

I just tried what you suggested and it worked! 🤦‍♂️

Thank you so much @proud flame

proud flame
#

Glad I could help :)