The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on September 22, 2021, 06:06:37 AM

Title: Vectors make life much easier
Post by: Biterider on September 22, 2021, 06:06:37 AM
Hi
A new container object has joined the ObjAsm arsenal.
It's called Vector, by analogy with a vector in other languages such as https://en.wikipedia.org/wiki/Sequence_container_(C%2B%2B)#Vector (https://en.wikipedia.org/wiki/Sequence_container_(C%2B%2B)#Vector)

It's also very similar to an XWordCollection, but lighter and almost interchangeable. Since it operates in a linear space, it is very fast.
It was written so that it could be compiled setting a few switches for different payload sizes like BYTE, WORD, DWORD or even QWORD.
This template can also be compiled for 32- and 64-bit targets.
Descendants can implement additional features like sorting or additional processing.
Serialization is supported like every other object via the Stream put and get methods. Unlike Collections, the payload is not serialized.

To demonstrate the use of Vectors, I added a new Demo(05) to the ObjAsm project, that will be released soon.
If you'd like some insight, you can download the latest development version from GitHub.

Due to the great versatility of the Collections, Vectors will certainly enjoy the same success.  :cool:

Biterider
Title: Re: Vectors make life much easier
Post by: HSE on September 23, 2021, 10:38:35 PM
Hi Biterider!

It's Collection an specific case of Vector (or more exactly a descendent of an specific case of Vector)?

Thanks, HSE.
Title: Re: Vectors make life much easier
Post by: Biterider on September 24, 2021, 03:34:49 AM
Hi HSE
This is an important question indeed. Collections and vectors have a very similar semantic interface that makes them interchangeable to a certain extent, but they are built in a slightly different way internally.
Collections were originally designed to manage a number of dynamically allocated objects. In the same sense, DataCollections process dynamically allocated memory blocks.
Vectors are simpler in that they store the payload data elements (BYTE..QWORD) in a single pre-allocated process heap memory block. That way, you save a lot of overhead dealing with memory allocations.
Does that sound familiar? Sure, this is how collections work internally to store the item pointers!  :cool:

So back to your question, no, they are indirectly related, both descended from Streamable but have a lot of similarities.

A typical use of a Vector is to maintain a list of HANDLEs that you will release at some point or a list of BYTEs that come from a communication device.
For some item sizes, you can use a DWCollection, QWCollection or XWCollection. They offer the same functionality.

Biterider
Title: Re: Vectors make life much easier
Post by: HSE on September 24, 2021, 05:51:19 AM
Thanks Biterider!

Quote from: Biterider on September 24, 2021, 03:34:49 AM
Does that sound familiar? Sure, this is how collections work internally to store the item pointers!  :cool:

A typical use of a Vector is to maintain a list of HANDLEs that you will release at some point or a list of BYTEs that come from a communication device.

I'm using collections mostly in that way  :biggrin: :biggrin: :biggrin:

Regards, HSE.