Odd question about bytes per reference.

wyrd

Senior Contributor
Joined
Aug 23, 2002
Messages
1,405
Location
California
String str = null;

I forget how much memory a pointer takes.. is it 2 bytes? And 1024 bytes per meg right?
 
Erk. *grabs heart in near heart attack* 4?! :eek: Holy smokes. I thought pointers just stored a 16 bit address... it's 32? That's crazy.

EDIT:

Err.. and speaking of which..

bits -> bytes -> kilobytes -> megs -> gigs

I think we were both wrong. Wouldn't it be 8 bits to a byte, 1024 bytes to a kilobyte, 1024 kilobytes to a meg and 1024 megs to a gig. So 1,048,576 bytes to a meg.

In which case what I was worried about doesn't matter. I was worried about a large array of reference types taking up a huge amount of memory. But perhaps not;

Assuming 4 bytes per reference, that's 524,288 references per meg (1048576 / 4). What I was previously thinking was 256 references per meg (1024 / 4). *blink*

I guess I was worrying for nothing. ;)
 
Last edited:
Oops I dunno what I was thinking....

1024^1 bytes = 1 KB
1024^2 bytes = 1 MB
1024^3 bytes = 1 GB

etc...


Also, you could be right about the 16-bit pointers.. I just thought pointers were 32-bit. 65535 bytes available for pointers just doesn't seem reasonable.
 
Heh.. well I suppose this is what I get for not keeping the book I used in Assembly class. I'm sure someone will come along and set this whole thing straight. ;)
 
I sure hope so. I've been wondering the same thing. If it is just 2 bytes I'll have to change some of my code around.
 
PlausiblyDamp said:
Pointers should be specific to the OS architecture. In a 32-bit version of windows a pointer needs to be able to address 4G of ram - therefore 32 bits long.

Ah, that would explain it. Gah, now I remember why I thought they were 16 bits. In assembly class we built programs built off of the 16 bit architecture to make things easier.
 
Back
Top