Array memory usage 
Author Message
 Array memory usage

Does anyone know how much memory an allocated, but unused
array uses? For instance, if I have an array of 1000
elements, but usually only use 100 or so, how much of a
overhead it is having the extra 900 allocated?


Thu, 28 Oct 2004 13:55:35 GMT  
 Array memory usage
Depends on what type of array.

    For Value Types, the entire array is allocated at creation, so that an
array of 1000 int's (4 bytes each) is 4000 bytes.  1000 doubles will take
8000 bytes.  An array of structs will take 1000 * <however many bytes the
array is>  (with any byte alignment characteristics to consider as well).
    For Reference types, well, I won't pretend to know exactly how many
bytes they might have hidden away for each reference, though, there will at
least be a hidden pointer, so I'd guess a minimum of 4000 bytes there as
well, assuming 32 bit reference pointers. But, you would only have your 100
objects created, the other 900 would be null.

Hope this helps,
Chris R.


Quote:
> Does anyone know how much memory an allocated, but unused
> array uses? For instance, if I have an array of 1000
> elements, but usually only use 100 or so, how much of a
> overhead it is having the extra 900 allocated?



Fri, 29 Oct 2004 01:02:17 GMT  
 Array memory usage
Thanks Chris

Quote:
>-----Original Message-----
>Depends on what type of array.

>    For Value Types, the entire array is allocated at

creation, so that an
Quote:
>array of 1000 int's (4 bytes each) is 4000 bytes.  1000
doubles will take
>8000 bytes.  An array of structs will take 1000 *

<however many bytes the
Quote:
>array is>  (with any byte alignment characteristics to
consider as well).
>    For Reference types, well, I won't pretend to know
exactly how many
>bytes they might have hidden away for each reference,

though, there will at
Quote:
>least be a hidden pointer, so I'd guess a minimum of
4000 bytes there as
>well, assuming 32 bit reference pointers. But, you would
only have your 100
>objects created, the other 900 would be null.

>Hope this helps,
>Chris R.



Fri, 29 Oct 2004 20:04:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Thanks: pointer to array - memory usage

2. pointer to array - memory usage

3. Thanks: pointer to array - memory usage

4. Free memory, memory usage

5. Determining Memory Usage

6. Windows Service Memory Usage

7. Video Memory Usage in C Programs

8. Windows Services and Memory usage

9. custom malloc()free() to record memory usage?

10. C# Memory usage.

11. CollectionBase memory usage/leakage?

12. memory usage

 

 
Powered by phpBB® Forum Software