Data Packs

A new feature introduced in SourceMod is “data packs.” Before explaining what these are, let’s look at why they exist.

Observe the set_task function in AMX Mod X. It allows you to pass an arbitrary array of data onto the timer callback. This is ugly, as it requires bitpacking. Worse, it means the entire array has to be copied into each successive call.

As ugly as this is, we probably still would have done it in SourceMod, except for the fact that — we can’t. The String tag does not coalesce to any other tag properly, and thus it is impossible to pack strings through. That’s not acceptable.

Instead, commands such as CreateTimer (might not be public by the time this article is released) take in a Handle. This way, you can pass one Handle through asynchronous functions. It’s much faster to copy an integer than an array, and you can pass any Handle type.

However, users still need to be able to pack data into a structure for asynchronous calls. Thus, we created the DataPack type. A DataPack is simply a buffer of memory that stores whatever you write to it. You can write floats, cells, and strings. The DataPack itself is a Handle, so you can pass it through asynchronous functions. And as a special convenience, there is a CreateTimer function which explicitly handles allocation and deallocation of a DataPack for you.

Other places DataPacks will probably get used are the SortCustom1D/SortCustom2D functions, as well as SQL_ThreadQuery.

2 Responses to “Data Packs”

  1. CyberMind says:

    Will these datapacks function like bf_write/bf_reads?

  2. BAILOPAN says:

    Pretty much the same, except bytewise and not bitwise.

Leave a Reply

You must be logged in to post a comment.