-
Notifications
You must be signed in to change notification settings - Fork 1
VLA Considerations
Personally, I do not believe the VLA (or alloca
) to be the evil that some "by the book" developers do. Simple, stack-based, "size-determined-at-runtime" storage has its legitimate place as a developer tool. I do understand, however, why academics don't want it available. Students may lack grasp of its underpinnings, rely too readily on or abuse it, then indefinitely write time-bomb code.
Here in this project, VLA use is deliberate, in localized instances — small functions where they free as soon as those functions return — never for long-term or in iterative cases where their allocations could accumulate or "stack up." 🤓
If VLAs bother you, you can change them in your fork of this project. Replace with the "somewhat more standard, or deliberate"alloca
or of course with std::vector
, although it's heavier (there's no direct std::
equivalent for lightweight runtime-sized arrays).
To assist, I set -Werror=vla
as a Clang - Custom Compiler Flag and Continue building after errors
to list them for you here:
Vulkan/Assist/ValidationLayers.cpp
ValidationLayers::getVulkanInstanceLayers()
1. VkLayerProperties instanceLayerProperties[nLayerProperties];
Vulkan/Objects/Swapchain.cpp
Swapchain::createImageViews()
2. VkImage images[nImages];
Vulkan/Objects/GraphicsDevice.cpp
GraphicsDevice::selectGPU(...)
3. VkPhysicalDevice physicalDevices[nPhysicalDevices];
GraphicsDevice::pickBestDevice(...)
4. int ranks[nDevices];
Vulkan/Objects/DeviceQueues.cpp
DeviceQueues::DetermineFamilyIndices(...)
5. VkQueueFamilyProperties familyProperties[nFamilies];
Vulkan/Assist/DeviceAssessment.cpp
DeviceAssessment::assayDeviceExtensionSupport(...)
6. VkExtensionProperties extensionProperties[nDeviceExtensions];
DeviceAssessment::assaySurfaceFormatSupport(...)
7. VkSurfaceFormatKHR formats[nFormats];
DeviceAssessment::assayPresentModeSupport(...)
8. VkPresentModeKHR presentModes[nModes];
Vulkan/AddOns/Descriptors.cpp
Descriptors::createDescriptorSetLayout()
9. VkDescriptorSetLayoutBinding layoutBindings[numDescribers];
Descriptors::createDescriptorPool()
10. VkDescriptorPoolSize poolSizes[numDescribers];
Descriptors::createDescriptorSets()
11. VkWriteDescriptorSet descriptorWrite[numDescribers];