|
-
Mar 26th, 2003, 12:12 PM
#1
Thread Starter
Frenzied Member
Type Variables and memory organization?
How is PC memory organized? It is accessed byte by byte or are there larger access units?
I have an application with an array of user type variables. I noticed that when a user Type variable is written to a file, all the subordinate variables are packed with no filler. How do these subordinate variables appear in memory?
On a mainframe, the order of the variables in an input/output record affects the amount of memory required. Does it have an effect for a VB program?
Suppose I have Type variable with a subordinate 9-character fixed string and some subordinate Doubles. If The string is first, is there unused space between it and the first double? Will defining the subordinate doubles first save some memory space?
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 26th, 2003, 02:05 PM
#2
Fanatic Member
You can currently purchase 1Gig of RAM for under $200 (US).
I am not dismissing your question, but I don't believe Visual basic has that kind of
control over how items are loaded. The VBcompiler smashes data as close as it can.
I do not belive there is any one-to-one way to know what values are stored in memory vs how an output
file is ordered.
I would think VB has many other performance pitfalls than re-ordering your type.
-
Mar 26th, 2003, 02:17 PM
#3
Frenzied Member
I have always had to be aware of alignment on every system that I have ever worked on. Mostly because of the fact that the data is being passed between apps that were coded in different languages. Some languages like COBOL and VB do not make it apparent that they are aligning the variables in a structure to the correct alignment.
I put the following code in an empty form
VB Code:
Private Type dclTest
strText As String * 9
dblOne As Double
dblTwo As Double
End Type
Private Declare Sub CopyMemory Lib "KERNEL32" _
Alias "RtlMoveMemory" (hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Private Sub Form_Load()
Dim testUDT As dclTest
Dim b As Byte
Dim i As Integer
With testUDT
.strText = "str len 9"
.dblOne = 200
.dblTwo = 5.5
End With
Debug.Print "UDT is " & LenB(testUDT) & " bytes long"
For i = 0 To LenB(testUDT) - 1
CopyMemory b, ByVal VarPtr(testUDT) + i, 1
Debug.Print b;
Next i
End Sub
and got the following output:
UDT is 36 bytes long
115 0 116 0 114 0 32 0 108 0 101 0 110 0 32 0 57 0 0 0 0 0 0 0 0 0 105 64 0 0 0 0 0 0 22 64
This would indicate that 2 pad bytes were inserted after the String to properly align the Doubles.
strText = 18 bytes
padding = 2 bytes
dblOne = 8 bytes
dblTwo = 8 bytes
This is a rather round-about way of getting the individual bytes, but I'm not the most knowledgable VB programmer and don't know if there is a better way to do it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|