[Done] Why CatchXML needs more memory then LaodXML?

Post bugreports for the Mac OSX version here
Lebostein
Addict
Addict
Posts: 854
Joined: Fri Jun 11, 2004 7:07 am

[Done] Why CatchXML needs more memory then LaodXML?

Post by Lebostein »

Compare case 1 and 2. In both cases the 1 GB XML file is loaded in memory first. In case 1 I use CatchXML from that memory, in case 2 I load the file again from disk. In both cases the same amount of memory is availabe, but case 1 fails, case 2 works.

Code: Select all

filename$ = "/Users/lebostein/x.xml"

; Load file into memory
fileid = ReadFile(#PB_Any, filename$)
*memory = AllocateMemory(Lof(fileid))
ReadData(fileid, *memory, MemorySize(*memory))
CloseFile(fileid)

Select 1

  Case 1

    ; Catch XML from memory above
    XML = CatchXML(#PB_Any, *memory, MemorySize(*memory))
    If XMLStatus(XML): Debug XMLError(XML): Else: Debug "OK": EndIf ; ---> "out of memory"

  Case 2

    ; Load XML from disc
    XML = LoadXML(#PB_Any, filename$)
    If XMLStatus(XML): Debug XMLError(XML): Else: Debug "OK": EndIf ; ---> OK

EndSelect
Fred
Administrator
Administrator
Posts: 18498
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why CatchXML needs more memory then LaodXML?

Post by Fred »

Any chance to share you XML (in PM if you want) ?
infratec
Always Here
Always Here
Posts: 7781
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Why CatchXML needs more memory then LaodXML?

Post by infratec »

What is the result of this:

Code: Select all

; Load file into memory
fileid = ReadFile(#PB_Any, filename$)
If FileID
  *memory = AllocateMemory(Lof(fileid))
  If *memory
    If ReadData(fileid, *memory, MemorySize(*memory)) <> MemorySize(*memory)
      Debug "Was not able to read all bytes"
    Else
      Debug "Ok"
    EndIf
  Else
    Debug "Was not able to allocate memory"
  EndIf
  CloseFile(fileid)
Else
  Debug "Was not able to open file"
EndIf
Fred
Administrator
Administrator
Posts: 18498
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why CatchXML needs more memory then LaodXML?

Post by Fred »

I think it's a limitation of expat, you need to use streaming for bigger file (we use this in loadxml() but not in catchxml). I will see what can be done
Fred
Administrator
Administrator
Posts: 18498
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Why CatchXML needs more memory then LaodXML?

Post by Fred »

I changed the way CatchXML works, feel free to test it
Post Reply