very simple question

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

very simple question

Post by cha0s »

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

Post by jofers »

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: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

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

Post by VirusScanner »

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

Post by Deleter »

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

Post by VirusScanner »

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

Post by jofers »

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

Post by Deleter »

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

Post by VirusScanner »

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:

Post by etko »

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

Post by 1000101 »

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

Post by Deleter »

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

Post by 1000101 »

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.
Post Reply