Re: UDT memory alignment
From: Bill McCarthy (bill_mcc_at_<)
Date: 02/26/04
- Next message: Bill McCarthy: "Re: UDT memory alignment"
- Previous message: Bill McCarthy: "Re: UDT and Recordset"
- In reply to: Larry Serflaten: "Re: UDT memory alignment"
- Next in thread: Jane Ransom: "Re: UDT memory alignment"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 26 Feb 2004 21:25:28 +1100
Hi Larry,
Yeh, it in both Vb5 and VB6, UDTS are dword aligned. Vb5 had a problem that
LenB did not report the actual aligned length (I seem to recall there was/is
a KB and some nasty workaround for that <g>)
"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:eIzym04%23DHA.2316@tk2msftngp13.phx.gbl...
> "Ian" <notreadingyourcrap@hotmail.com> wrote
> > If comprised of nothing larger
> > than byte, integer, boolean (but has at least 1 integer or boolean,
which
> > are word aligned) then VB will allocate space in 2 byte increments. If
> > there is at least one variable of any other kind (which are all larger)
then
> > it will allocated space in 4 byte increments.
>
> I tested and found that to be true in VB5 also.
>
> Private Type Test
> b1 As Byte
> i1 As Integer
> End Type
>
> That will be 4 bytes.
>
> Private Type Test
> b1 As Byte
> i1 As Long
> End Type
>
> And that will be 8, but adding extra bytes at the end still
> require only one byte each:
>
> Private Type Test
> b1 As Byte
> i1 As Long
> b2 As Byte
> b3 As Byte
> End Type
>
> Here b2 and b3 are not padded, so it uses only 10 bytes total.
> Again, this was in VB5, but from what you say, VB6 would
> report 12 bytes.
>
> Unfortunately, VB5 does the same sort of padding when
> working with arrays. The type like the one listed above
> reports using only 10 bytes, but they actually use 12 in an
> array:
>
> Private Sub Form_Load()
> Dim Ary(3) As Test
>
> Debug.Print LenB(Ary(0)) ' 10
> Debug.Print VarPtr(Ary(0).b1) ' 1532504
> Debug.Print VarPtr(Ary(1).b1) ' 1532516
> Debug.Print VarPtr(Ary(2).b1) ' 1532528
>
> End Sub
>
> Its certainly is something to keep an eye on when using types!!!
>
> LFS
>
>
>
- Next message: Bill McCarthy: "Re: UDT memory alignment"
- Previous message: Bill McCarthy: "Re: UDT and Recordset"
- In reply to: Larry Serflaten: "Re: UDT memory alignment"
- Next in thread: Jane Ransom: "Re: UDT memory alignment"
- Messages sorted by: [ date ] [ thread ]