CopyMemory and Arrays: Proper Use


It is no secret VB is more often than not, a language that produces relatively slow machine code. This is the price we, VB programmers, pay for its extremely ease of use. But there have always been people trying to improve this slowness intrinsic in all VB programs. An example of this is the use of Windows API functions. They provide extremely fast access and processing of data. Of course, once you start using that, you stop getting a few benefits from the Visual Basic libraries, such as automatic reallocation of buffers and such. But hey, I think it is an OK price for what we get. I completely support the use of APIs and tricks in VB. They are good improvements to VB, and they are fun (most of the time).

In this small article, I will be showing how to use the CopyMemory API sub (known as rtlMoveMemory) to keep an array sorted all the time without much hassle, and by hassle I mean a For..Next loop. Such a loop is normally fast, but when you are handling lots of data, and you continously insert and remove items, this loop becomes a bottleneck for the program flow.

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”