We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

[3367] CopyMemory and Arrays: Proper Use

Last post 06-26-2004 7:49 AM by kwadrofonik. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [3367] CopyMemory and Arrays: Proper Use

    This thread is for discussions of CopyMemory and Arrays: Proper Use.

    • Post Points: 0
  • 03-01-2003 11:03 AM In reply to

    DWORD padding.

    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 with this later...
    • Post Points: 0
  • 03-01-2003 1:25 PM In reply to

    • webjose
    • Top 10 Contributor
    • Joined on 01-02-2002
    • Guru
    • Points 11,015

    Interesting case

    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, starting with a WORD is not enough.  The following will get DWORD-aligned, meaning you must not have DWORDS or QWORDS.

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

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

    Private Type MyType
       var1 As Integer
       var3 As Double
    End Type

    Thanks for the observation.  I will update the article to add the finding.
    • Post Points: 0
  • 06-26-2004 7:49 AM In reply to

    ReDimm statement is innefficient

    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 order to change the dimension. In fact, using the CopyMemory function for this purpose is useful as well. A good compromise would be to redimension the array every 20th iteration and then check for empty array values, such as:

    If SubDirCount = UBound(DirList) Then ReDim Preserve DirList(UBound(DirList) + 20)

    an even better solution is to use an array object.
    • Post Points: 0
Page 1 of 1 (4 items)