WootingKb / wooting-analog-sdk

Native support for Analog Keyboards #WootDev
Mozilla Public License 2.0
131 stars 19 forks source link

Device Enumerating is Done Odd #69

Open Karutoh opened 7 months ago

Karutoh commented 7 months ago

So this is an odd way to enumerate devices at runtime as shown below.

WootingAnalog_DeviceInfo_FFI* buffer = nullptr;

int len = wooting_analog_get_connected_devices_info(nullptr, 0xFFFFFFFF);

buffer = new WootingAnalog_DeviceInfo_FFI[len];

wooting_analog_get_connected_devices_info(&buffer, len);

It should be done this way so there's no mistake on how it's done. As this method is typically common.

WootingAnalog_DeviceInfo_FFI* buffer = nullptr;
unsigned int size = 0;

wooting_analog_get_connected_devices_info(nullptr, &size); // Given buffer is a "nullptr" which will set the "size" variable.

buffer = new WootingAnalog_DeviceInfo_FFI[size];

wooting_analog_get_connected_devices_info(&buffer, &size); // Here the array is actually set.
Sainan commented 7 months ago

This would be a breaking change. Instead, maybe something like wooting_analog_get_num_connected_devices so you can do your dynamic allocation.

Karutoh commented 7 months ago

This would be a breaking change. Instead, maybe something like wooting_analog_get_num_connected_devices so you can do your dynamic allocation.

I think that would be a good compromise.