Page 1 of 1

[Done] Why CatchXML needs more memory then LaodXML?

Posted: Wed Jan 07, 2026 7:33 am
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

Re: Why CatchXML needs more memory then LaodXML?

Posted: Wed Jan 07, 2026 11:19 am
by Fred
Any chance to share you XML (in PM if you want) ?

Re: Why CatchXML needs more memory then LaodXML?

Posted: Wed Jan 07, 2026 5:31 pm
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

Re: Why CatchXML needs more memory then LaodXML?

Posted: Wed Jan 07, 2026 6:09 pm
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

Re: Why CatchXML needs more memory then LaodXML?

Posted: Thu Jan 08, 2026 2:50 pm
by Fred
I changed the way CatchXML works, feel free to test it