ReAllocateMemory-WinXP~Win98(PB4/3.94)

Just starting out? Need help? Post your questions and find answers here.
Toshy
User
User
Posts: 15
Joined: Fri Feb 17, 2006 3:38 am

ReAllocateMemory-WinXP~Win98(PB4/3.94)

Post by Toshy »

My original topic:
forums.purebasic.com/german/viewtopic.php?p=77544#77544

I don`t speak englisch. Only some words. :-(

I found a bug in PB4 beta 3 an PB3.94 under Windows98. I don`s know whether it an Bug of Windows or PB.

The Memory-Pointer (ID) of ReAllocateMemory() increases up to 2 GB oder over 2 GB. That don`t work. In WindowsXP exists no error.

[edit] Code was edit: "size.l" change to "32*i"

Code: Select all

OpenConsole()
PrintN("start") : Debug "start"
*MEM = AllocateMemory(16)
*MEM2
StartTime.l
For i = 1 To 800000 ; *1000
  If ElapsedMilliseconds()-StartTime > 1000
    PrintN("Ausgabe sekndlich | i="+Str(i) +" | *MEM=" + Str(*MEM ) )
    Debug "*MEM=" + Str(*MEM )
    StartTime = ElapsedMilliseconds()
  EndIf
  *MEM2 = *MEM
  Repeat
    *MEM = ReAllocateMemory(*MEM2, 32*i) ; man kann auch nur "i" nehmen
    If *MEM = 0
      PrintN("_ReAllocateMemory()-Error | i=" + Str(i) + " | Size=" + Str(32*i) + " | *MEM2=" + Str(*MEM2) )
      Debug "_ReAllocateMemory()-Error | i=" + Str(i) + " | Size=" + Str(32*i) + " | *MEM2=" + Str(*MEM2) 
      Delay(5000)
    EndIf
  Until *MEM <> 0
Next i
PrintN("ende") : Debug "ende"
For i = 1 To 600
  Delay(100)
Next i
CloseConsole()
debug Windows98(debugger):
start
*MEM=8978444
*MEM=189857804
*MEM=372899852
*MEM=563019788
*MEM=754909196
*MEM=943521804
*MEM=1132724236
*MEM=1322123276
*MEM=1505951756
*MEM=1694564364
*MEM=1887895564
*MEM=2080047116
_ReAllocateMemory()-Error | i=184192 | Size=5902336 | *MEM2=2133131276
debug Windows XP(console):
start
Ausgabe sek³ndlich | i=1 | *MEM=3350160
Ausgabe sek³ndlich | i=34560 | *MEM=6422560
Ausgabe sek³ndlich | i=43904 | *MEM=6750240
Ausgabe sek³ndlich | i=52736 | *MEM=5308448
Ausgabe sek³ndlich | i=58112 | *MEM=7208992
Ausgabe sek³ndlich | i=64128 | *MEM=7405600
Ausgabe sek³ndlich | i=68224 | *MEM=7536672
Ausgabe sek³ndlich | i=72832 | *MEM=7667744
Ausgabe sek³ndlich | i=77056 | *MEM=5308448
Ausgabe sek³ndlich | i=80640 | *MEM=5308448
Ausgabe sek³ndlich | i=84096 | *MEM=10747936
Ausgabe sek³ndlich | i=87808 | *MEM=8126496
Ausgabe sek³ndlich | i=92288 | *MEM=11272224
Ausgabe sek³ndlich | i=96896 | *MEM=8454176
Ausgabe sek³ndlich | i=100608 | *MEM=5308448
Ausgabe sek³ndlich | i=103936 | *MEM=8650784
Ausgabe sek³ndlich | i=107520 | *MEM=8781856
Ausgabe sek³ndlich | i=109824 | *MEM=5308448
.....
....
Bye
Toshy
Last edited by Toshy on Fri Feb 17, 2006 6:53 pm, edited 4 times in total.
!! sorry, i only speak some words in english. !!
1. AMD,3 GB MB-RAM,WinXP
2. Linux-TabletPC
Inet: 7 Kbyte/s Down/7Kbyte (not MBit) Up
PB4.6x
Messenger: Trillian (yahoo, skype, MSN/Live,icq)
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Post by Lebostein »

2080047116 Bytes are 2,08 GB. How many main memory you have? 2 GB RAM? :wink:
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The problem here is you ask a big continous chunk of memory, which isn't sure to be reserved. Win98 is also known as being quite weak when dealing with a lot of memory..
Toshy
User
User
Posts: 15
Joined: Fri Feb 17, 2006 3:38 am

Post by Toshy »

Oh god, my english :-(
i understand only some of your answer.
note: *MEM=2080047116 ist NOT the SIZE of Allocate Memory, it is the startpositon of Memory.
The error returns at i=184192 and that is (*32) a size of 5894144 Bytes (5 MB), NOT 2 GB.

The error exists in Win98, not XP. In WindowsXP the same Code / Exe returns a *memID that not increase. There the *MemId change to positions in Memory it`S free after Resize.

remarks:
Error at a used size of 5 MB and a *MemID at 2 GB
[edit]
Same Bug with AllocateMemory:

Code: Select all

OpenConsole()
PrintN("start") : Debug "start"
*MEM = AllocateMemory(16)
*MEM2
StartTime.l
For i = 1 To 800000*1000
  If ElapsedMilliseconds()-StartTime > 1000
    PrintN("1/Sek.| i="+Str(i)+" | MemorySize="+Str(32*i)+"/=" +Str((32*i)/(1024*1024))+"MB | *MEM=" + Str(*MEM ) )
    Debug "*MEM=" + Str(*MEM )
    StartTime = ElapsedMilliseconds()
  EndIf
  *MEM2 = *MEM
  FreeMemory(*MEM2) ; test for allocatememory
  errorcounter = 0
  Repeat
    ;*MEM = ReAllocateMemory(*MEM2, 32*i) ; man kann auch nur "i" nehmen
    *MEM = AllocateMemory(32*i) ; test for allocatememory
    If *MEM = 0
      PrintN("_ReAllocateMemory()-Error | i=" + Str(i) + " | Size=" + Str(32*i) + " | *MEM2=" + Str(*MEM2) )
      Debug "_ReAllocateMemory()-Error | i=" + Str(i) + " | Size=" + Str(32*i) + " | *MEM2=" + Str(*MEM2) 
      Delay(5000)
    EndIf
  Until *MEM <> 0
Next i
PrintN("ende") : Debug "ende"
For i = 1 To 600
  Delay(100)
Next i
CloseConsole()
Last edited by Toshy on Fri Feb 17, 2006 7:40 pm, edited 1 time in total.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Following doesn't concerns friedrichs' problem but this quotation:
Fred wrote:The problem here is you ask a big continous chunk of memory, which isn't sure to be reserved. Win98 is also known as being quite weak when dealing with a lot of memory..
Why is it possible to reserve a memory buffer with a size like this one:

Code: Select all

*Buffer.l = AllocateMemory(5000000000000000)
Debug *Buffer
Shouldn't AllocateMemory return 0 because of the enormous size given as parameter? I mean noone has a RAM of this size ... why does it give back a pointer, though?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

because it takes a only long, so your big value will overflow. Try to cast it in a long to see which real value it takes.
Toshy
User
User
Posts: 15
Joined: Fri Feb 17, 2006 3:38 am

Post by Toshy »

@fred
had you test my code?
A german user have test it an confirmed the problem.
!! sorry, i only speak some words in english. !!
1. AMD,3 GB MB-RAM,WinXP
2. Linux-TabletPC
Inet: 7 Kbyte/s Down/7Kbyte (not MBit) Up
PB4.6x
Messenger: Trillian (yahoo, skype, MSN/Live,icq)
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Fred wrote:because it takes a only long, so your big value will overflow. Try to cast it in a long to see which real value it takes.
OK ... I tested it:

Code: Select all

Size.l = 5000000000000000
Debug "Size: " + Str(Size) + " Bytes"
Debug "Size: " + Str(Size/1000/1000) + " MB"

*Buffer.l = AllocateMemory(Size) 
Debug "Pointer: "+Str(*Buffer)
And that were the results:
Debugger wrote:Size: 937459712 Bytes
Size: 937 MB
Pointer: 19267616
So there are still 937 MB reserved although I only have 512 MB RAM. So the problem still exists, if I do not make a serious mistake in thinking.
Dummy
Enthusiast
Enthusiast
Posts: 162
Joined: Wed Jun 09, 2004 11:10 am
Location: Germany
Contact:

Post by Dummy »

Christian wrote:So there are still 937 MB reserved although I only have 512 MB RAM. So the problem still exists, if I do not make a serious mistake in thinking.
maybe the memory is allocated half in the ram and half in the pagefile
(omg that was my worst english - sorry xD)
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hm ... so that would mean that this 'possibitlity' to reserve more memory than I have is a Windows related thing!? Is it, Fred? Or how does it come that the example above works. I even can fill the memory so the information is definitely stored anywhere ...
Thomas
Enthusiast
Enthusiast
Posts: 112
Joined: Sat Apr 26, 2003 8:45 pm

Post by Thomas »

The amount of available RAM is limited by your harddisk space (pagefile size). The only concern is performance when Windows starts swapping memory areas to / from disk.
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

I see ... so it's like Dummy said. Thanks to both of you for clearing that up ... :)

Regards,
Christian
Toshy
User
User
Posts: 15
Joined: Fri Feb 17, 2006 3:38 am

Post by Toshy »

in Windows98 you can only allocate a Memorysize () of the size of "physical memory" [*mem = allocateMemory(physicalmemorysize)] and the pagefile size can be 4 GB (oder 2gb?)

i found the problem of the "ReAllocateBug", it ist Windows98.
LocalAlloc() (WindowsAPI) returns the same Problem :-(
It's not a Purebasicbug, ist a WIndow's "structurebug" :-((((((

Thank's for your help.
The Topic can be cloesed.

Bye
Toshy
!! sorry, i only speak some words in english. !!
1. AMD,3 GB MB-RAM,WinXP
2. Linux-TabletPC
Inet: 7 Kbyte/s Down/7Kbyte (not MBit) Up
PB4.6x
Messenger: Trillian (yahoo, skype, MSN/Live,icq)
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Look at the description of the API command "GlobalAlloc" AND "HeapAlloc":
Windows Me/98/95: The heap managers are designed for memory blocks smaller than four megabytes. If you expect your memory blocks to be larger than one or two megabytes, you can avoid significant performance degradation by using the VirtualAlloc or VirtualAllocEx function instead.
I do not know, which API command is used by PureBasic!

cu, helpy
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

PB use the regular heap functions, i have overlooked this limitation. It's possible to workaround this, but it sounds a bit tricky as we will have to flags each memory block to now if it has been allocated by HeapAlloc() or VirtualAlloc().
Post Reply