Open main menu

UESPWiki β

Daggerfall Mod:DFRemake/Resource - Storing Data

< Mod / Daggerfall: Daggerfall Mod: DFRemake(Redirected from Daggerfall:DFRemake/Resource - Storing Data)

There are a few ways to store and access resources within DarkBasic.


User Defined TypesEdit

It is important to note the limitations of user defined types (UDT) within DarkBasic.

  • Like other types, UDTs are passed by value into functions
  • UDTs cannot be returned by functions
  • UDTs cannot be passed into DLLs (not directly or very easily at any rate)
  • UDTs cannot contain arrays


ListsEdit

Lists, or dynamic arrays, are the obvious choice for storing resouce types. Given the limitations of how things can be passed to/from functions, they will need to be accessed globally (all arrays are global by default).


PerformanceEdit

  • Although a while loop is ideal for iterating through lists, it is much slower (up to 6000 times slower) than for loops due to built-in sync/update code. For this reason one should always use for loops to iterate lists.
  • Simple iteration/comparison takes roughly 1 ms per 10000 elements (roughly linear).
  • Adding items at the bottom of the list appears to be non-linear as the number of elements in the list increases. For instance adding 100 elements takes 0.25 ms, 1000 takes 15 ms, 10000 takes 1500 ms.
  • There appears to be no speed difference between adding items from the top or at the bottom.
  • Time taken to add elements is based on their size ,especially for UDTs. For example, adding 10000 BYTEs takes 1300 ms, 10000 DWORDs takes 1500 ms, 10000 UDTs (1 field, 4 bytes total) takes 2100 ms, and 10000 UDTs (3 fields, 9 bytes total) takes 7000 ms.
  • When iterating in a for loop, storing the ARRAY COUNT() in a local variable is slightly faster. For example, iterating 10000 DWORDS takes 0.86 ms with a local and 1.1 ms with the function (~25% slower).
  • It is important to note that the ARRAY COUNT() command actually returns the last index in the list, as opposed to the number of elements. Since lists are 0-based this is a 1-record difference. Thus, in a for loop we must iterate from 0 to ARRAY COUNT() rather than 1 to ARRAY COUNT() or 0 to ARRAY COUNT()-1.
  • Deleting elements takes about the same time as adding elements. For example, deleting 10000 DWORDS takes 1150 ms.