Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / December 2005

Tip: Looking for answers? Try searching our database.

Structure Memory Usage?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 07 Dec 2005 16:35 GMT
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  2MB (index 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?.
Note: I need to dinamically increase each byteA, example:
Redim ptrArray(0).byteA(1)
Redim ptrArray(1).byteA(300)
Redim ptrArray(2).byteA(50)

2) Is ther any way (not Windows Task Manager) to know how much memory a
variable, or structure is using in vb.net?.

Thanks,

James
Mattias Sjögren - 07 Dec 2005 17:46 GMT
James,

Was there something wrong with the replies you got in the VB
newsgroup?

>I need help with a couple of questions, I have create and structure like:
>Structure byteArray
[quoted text clipped - 3 lines]
>
>Public ptrArray() As byteArray

I don't see the need for the strucure. Why don't you just do

Public ptrArray()() As Byte

>1) It seems that an structure increase the memory usage (I suppose it create
>internal variables).

No the structure doesn't add any additional overhead. But each array
object does, it needs to keep track of its size for example.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

James - 09 Dec 2005 07:16 GMT
Thanks Mattias for your answer.
I think that using Public ptrArray()() As Byte, I can not dinamically change
both dimensions, that is I need something like:

ptrArray(1)(200) -> 200 bytes array
ptrArray(2)(20) -> 20 bytes array
ptrArray(3)(100) -> 100 bytes array

Is that possible?.

One of my questions was: How can I know the memory usage of a variable,
class, array, ... in VB.NET, that is is there a command like SIZEOF in C?
(somebody suggested to post this question here).

Thanks,

James

> James,
>
[quoted text clipped - 21 lines]
>
> Mattias
Mattias Sjögren - 10 Dec 2005 11:16 GMT
>that is I need something like:
>
[quoted text clipped - 3 lines]
>
>Is that possible?.

Yes

>One of my questions was: How can I know the memory usage of a variable,
>class, array, ... in VB.NET, that is is there a command like SIZEOF in C?
>(somebody suggested to post this question here).

No there's no sizeof operator. The size is not available from managed
code. You can get the information from a profiler or debugger if you
really want to know.

Generally for arrays the size is the element size times the number of
elements, plus a small fixed overhead for the array descriptor.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.