# Improved API usage

**URL:** <https://qa.fmod.com/t/improved-api-usage/22185>\
**Category:** FMOD Engine\
**Tags:** unity, csharp\
**Created:** [October 14, 2024, 12:56pm UTC](https://qa.fmod.com/t/improved-api-usage/22185 "2024-10-14T12:56:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arfus](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Arfus](https://qa.fmod.com/u/Arfus)\
**Post date:** [October 14, 2024, 12:56pm UTC](https://qa.fmod.com/t/improved-api-usage/22185/1 "2024-10-14T12:56:36Z")

</div>

Hi there, I wanted to propose the addition of the following API calls to reduce the amount of object allocations. And hopefully make it a bit easier to retrieve some data.

**Retrieving data by index**

The following API calls I’m proposing to allow retrieving data without having to allocate a new array with every getXXXList invocation. Additionally `getParameterDescriptionByIndex` is also available, so it would be following the same format.

- `public RESULT getBankByIndex(int index, out Bank bank)`
- `public RESULT getEventDescriptionByIndex(int index, out EventDescription eventDescription)`

**Improved parameter retrieval**

The following API calls I’m proposing as `PARAMETER_DESCRIPTION` includes a guid. Additionally retrieving `EventDescription` and `Bank` is possibly through a guid. It would probably be needed to clarify that this would return the parameter description based on the parameter preset. I’m not sure if this is something that’s desired. However, it would make it a lot easier to retrieve parameters as you don’t have to iterate through banks → event descriptions → parameters to try and find a parameter.

- `public RESULT getParameterDescriptionById(GUID guid, out PARAMETER_DESCRIPTION parameterDescription)`
- `public RESULT getParameterDescriptionByPath(string path, out PARAMETER_DESCRIPTION parameterDescription)`

**Small Side Note**  
I’m currently storing/retrieving my object references by `System.Guid` instead of the `FMOD.GUID` object provided by FMOD. Converting from a `System.Guid` to an `FMOD.GUID` allocates a byte array. Which isn’t required if the conversion is done using [System.Guid.TryWriteGuid](https://learn.microsoft.com/en-us/dotnet/api/system.guid.trywritebytes?view=net-8.0) where the required `Span<byte>` refers to a `static readonly byte[]` which is already sized accordingly.

For example:

```csharp
private static readonly byte[] byteBuffer = new byte[16];

public GUID(Guid guid)
{
	Span<byte> bytesBuffer = byteBuffer.AsSpan();
	if (guid.TryWriteBytes(bytesBuffer))
	{
		Data1 = BitConverter.ToInt32(bytesBuffer[..4]);
		Data2 = BitConverter.ToInt32(bytesBuffer.Slice(4, 4));
		Data3 = BitConverter.ToInt32(bytesBuffer.Slice(8, 4));
		Data4 = BitConverter.ToInt32(bytesBuffer[12..]);
	}
	else
	{
		Data1 = 0;
		Data2 = 0;
		Data3 = 0;
		Data4 = 0;
	}
}

```

---

<div class="post-metadata">

**Author:** ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)\
**Post date:** [October 17, 2024, 1:45am UTC](https://qa.fmod.com/t/improved-api-usage/22185/2 "2024-10-17T01:45:57Z")

</div>

Hi,

Thank you for the detailed suggestions! I have passed them on to our development team to investigate further.
