Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 47,479 times

Contents

Downloads

Related Categories

CopyMemory and Arrays: Proper Use - Introduction

webjose

Introduction

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.

This code is for everyone's use and, although I have tested it the best I can, I cannot be held responsible for its use or misuse, or for any other type of damage WHATSOEVER. Use this code at your own risk. If you find an error or can improve it, feel

Comments

  • ReDimm statement is innefficient

    Posted by kwadrofonik on 26 Jun 2004

    Thanks. Definately some good information, however...

    It is not very practical to use the ReDim statement each iteration of a loop since it copies the entire array to a different memory location in ...

  • Interesting case

    Posted by webjose on 01 Mar 2003

    I just tested and yes, you are correct.

    Private Type MyType
    var1 As Integer
    var2 As Byte
    var3 As Boolean
    End Type

    The above type will get padded to a WORD, not a DWORD. However,...

  • DWORD padding.

    Posted by BitShifter on 01 Mar 2003

    I'm willing to bet that if he first variable in the UDT had been an integer, the following Bytes would have been padded to WORD size and no more.

    This being the start of the week-end, I'll play wit...