"James" <in**@pricetech.es> schrieb
Hi,
I need help with a couple of questions, I have create and structure
like:
Structure byteArray
Public byteA() As Byte
End Structure
Public ptrArray() As byteArray
I have redim ptrArray(1000000) and the memory usage in Windows Task
Manager
shows an increase of 4MB bytes that seems OK.
Then I have done
for intI=1 to 1000000
Redim ptrArray(intI).byteA(1)
next intI
And now the memory in task manager shows and increase of almost 16
MB,
instead of 1MB.
You probably mean 2 MB because arrays are zero-based, and an upper bound of
1 creates the items 0 and 1.
QUESTIONS:
1) It seems that an structure increase the memory usage (I suppose
it create
internal variables). Is there any other way that I can have an
"Array of
Arrays" that can be dinamically increase without the memory overcost
of
using a structure?.
I don't know if it solves the memory issue, but and array of arrays can be
declared this way:
Public ptrArray()() As byte
This is an array of byte-arrays.
Public ptrArray(999999)() As byte
This is an array that can point to 1,000,000 byte arrays. Each of the 1 mio.
items is still Nothing.
Redim ptrArray(0)(99)
Now Item 0 points to an array of 100 bytes.
2) Is ther any way (not Windows Task Manager) to know how much memory a
variable, or structure is using in vb.net?.
I have no reliable answer to this. I can only point to
VB language reference -> data types -> data type summary.
There are few words about the memory consumption of arrays - maybe this
helps. Using that information: 1,000,000 * (12 + 8 + 2) = ~22 MB. But as I
said, I can not say this for sure, above all because the automatic memory
management is a "black box". Maybe you can ask this in the
microsoft.public.dotnet.framework.clr group because it is not really VB.Net
related.
Armin