very simple question

New to FreeBASIC? Post your questions here.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

very simple question

Postby cha0s » Mar 02, 2006 4:58

am i right to assume that windows will never return a negative mem address??

like,

l = callocate( 1 )

could l ever < 0 ??
jofers
Posts: 1525
Joined: May 27, 2005 17:18
Contact:

Postby jofers » Mar 02, 2006 5:13

Actually, there's a good chance it might be. Pointers are unsigned, so leading 1s are interpreted as a negative number if you use an signed type to hold your pointer.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Mar 02, 2006 5:26

ah okay, thanks...
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

Postby VirusScanner » Mar 02, 2006 19:37

But if you use a "ptr" type, it will never come out negative since pointers are treated as unsigned.
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Postby Deleter » Mar 02, 2006 20:11

I was wondering about something. If a pointer is actually a hardware address, then what happens when you exceed the range of 4 bytes? If you take (2^32)/1024^3=4 GB of memory. So what happens when i install more gb? I have a suspiscion that there is some knowledge concerning pointers that I lack, so if that is true, enlighten me. If not, what happens?
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

Postby VirusScanner » Mar 02, 2006 20:18

I doubt it's possible for a 32 bit processor to handle more than 4GB of memory. But 64 bit processors have 64 bit pointers, so it would be possible there.

If you do end up installing >4GB let us know what happens, I'd like to see if it can handle it. Maybe the extra is just ignored.
jofers
Posts: 1525
Joined: May 27, 2005 17:18
Contact:

Postby jofers » Mar 02, 2006 20:20

4gb of memory is a limit imposed by 32-bit processors (95% of desktops today). 64-bit CPUs like the Itanium and AMD64 use 64-bit addressing, which is really the main draw of those processors.

However, the number inside pointers doesn't actually specify the physical byte in memory you're accessing. "Protected Mode" CPUs (e.g. every CPU since the 386) allows for the OS to dish out "virtual memory" to each program. This prevents you from, say, writing to &ha000 and messing up the screen. So you could allocate up to 4gb (or to whenever Windows says "no more") inside program, and Windows would dump whatever memory can't fit in RAM on your hard drive (at the price of a very expensive speed cut).
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Postby Deleter » Mar 02, 2006 21:01

ah, so my 64bit processor can handle 16 exabytes of memory, thats good to know, lol. we only have a couple more units to go till thats reasonable ;). tera, peta, exa...lol
VirusScanner
Posts: 775
Joined: Jul 01, 2005 18:45

Postby VirusScanner » Mar 04, 2006 20:58

It looks like windows does support huge blocks of memory, but you have to be running a server to do it:
http://msdn.microsoft.com/library/defau ... ension.asp
etko
Posts: 113
Joined: May 27, 2005 7:55
Location: Slovakia
Contact:

Postby etko » Mar 11, 2006 4:23

32-bit processors from pIII up are able to use something like 36 TB or like that of memory, when you enable special segmented mode. It's kinda like 16 bit real mode, instead it's 32 bit segmented pmode ;). But there are segments & offsets so all that segment offset stuff returns. However I guess only some special scientific machines or what are set up that way.

Pointers you use in Windows point to "logical" memory, there is circuitry in CPU which translates these adresses into real physical ones. Even when your windows memory looks like you have 32 meg linear chunk, in reality it might be scattered all over your mem or HDD.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Mar 11, 2006 5:59

Not that it really matters since very few consumer board support anywhere near 4G of physical RAM. Generally you need to get a workstation/server motherboard for support of more then 2G of RAM.
Deleter
Posts: 975
Joined: Jun 22, 2005 22:33

Postby Deleter » Mar 11, 2006 17:58

well, the largest consumer oriented board I've seen supported 16 gb of ram. Besides, its only a few years before 4 gb is a lot more common, so maybe its not that important yet, but it will be soon enough.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Postby 1000101 » Mar 11, 2006 18:45

I suppose I should have clarified. For 32-bit CPUs they usually cap the board at 2G. For 64-bit boards, 16G doesn't surprise me. MY old 386 was capped at 4M.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 8 guests