Page 1 of 3

Feature Request 'SaveMemory' to Disk Drive

Posted: Sun Jun 26, 2022 4:57 pm
by Simo_na
EG

FillMemory (*Memory , Size , Value)
SaveMemory (0 , *Memory , Size , "data.tmp")

That works with any size of memory and has no limits of any kind.
Even to take a snapshot of 32 Gigabytes of RAM or more...

All the best.
Thank You :)

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Sun Jun 26, 2022 5:32 pm
by mk-soft
You programme something like that yourself

Code: Select all

;-TOP

Procedure SaveMemory(*Memory, Size, FileName.s)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure

-1

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Sun Jun 26, 2022 7:29 pm
by jacdelad
If you put the parameter Size last you can make it optional and make it even easier. Leaving it could trigger MemorySize().

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Sun Jun 26, 2022 10:49 pm
by Simo_na
mk-soft wrote: Sun Jun 26, 2022 5:32 pm You programme something like that yourself

Code: Select all

;-TOP

Procedure SaveMemory(*Memory, Size, FileName.s)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure

-1
mk-soft WriteData have 2GB limit
https://www.purebasic.fr/english/viewtopic.php?t=78697
thank you

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Sun Jun 26, 2022 10:54 pm
by Simo_na
jacdelad wrote: Sun Jun 26, 2022 7:29 pm If you put the parameter Size last you can make it optional and make it even easier. Leaving it could trigger MemorySize().
sorry
I did not understand, can you explain better?

thank you

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Mon Jun 27, 2022 4:56 am
by jacdelad
Parameters for functions can be optional, so you can make the function easier in case you want to write a whole memory block to disk:

Code: Select all

Procedure SaveMemory(*Memory, FileName.s, Size=-1)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    If Size = -1
      Size = MemorySize(*Memory)
    EndIf
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure
If you want to write the whole content of *Memory to disk, you don't need to specifiy Size.

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Mon Jun 27, 2022 10:42 pm
by Simo_na
jacdelad wrote: Mon Jun 27, 2022 4:56 am Parameters for functions can be optional, so you can make the function easier in case you want to write a whole memory block to disk:

Code: Select all

Procedure SaveMemory(*Memory, FileName.s, Size=-1)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    If Size = -1
      Size = MemorySize(*Memory)
    EndIf
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure
If you want to write the whole content of *Memory to disk, you don't need to specifiy Size.
jacdelad,
I can't figure out how to run your code, could you give me a complete real working example to save a size of 8 Gigs to file ?
Thank you

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 4:36 am
by jacdelad
Assuming you can allocate 8GB of memory:

Code: Select all

Procedure SaveMemory(*Memory, FileName.s, Size=-1)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    If Size = -1
      Size = MemorySize(*Memory)
    EndIf
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure

*mem=AllocateMemory(8*1024*1024*1024)
If *mem
  ;Fill your memory with whatever you want to
  save.s=SaveFileRequester("Save my 8GB of memory","Default.dat","Dat-Files|*.dat|All Files|*.*",0)
  If save<>""
    SaveMemory(*mem,save)
    ;SaveMemory(*mem,save,8*1024*1024*1024);Not needed if I save all data from *mem
  EndIf
  FreeMemory(*mem)
Else
  MessageRequester("Error","Couldn't assign 8GB of memory. :(",#PB_MessageRequester_Error)
EndIf

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 9:21 am
by Simo_na
jacdelad wrote: Tue Jun 28, 2022 4:36 am Assuming you can allocate 8GB of memory:

Code: Select all

Procedure SaveMemory(*Memory, FileName.s, Size=-1)
  Protected r1, file, cnt
  file = CreateFile(#PB_Any, FileName)
  If file
    If Size = -1
      Size = MemorySize(*Memory)
    EndIf
    cnt = WriteData(file, *Memory, Size)
    CloseFile(file)
    If cnt = Size
      r1 = #True
    EndIf
  EndIf
  ProcedureReturn r1
EndProcedure

*mem=AllocateMemory(8*1024*1024*1024)
If *mem
  ;Fill your memory with whatever you want to
  save.s=SaveFileRequester("Save my 8GB of memory","Default.dat","Dat-Files|*.dat|All Files|*.*",0)
  If save<>""
    SaveMemory(*mem,save)
    ;SaveMemory(*mem,save,8*1024*1024*1024);Not needed if I save all data from *mem
  EndIf
  FreeMemory(*mem)
Else
  MessageRequester("Error","Couldn't assign 8GB of memory. :(",#PB_MessageRequester_Error)
EndIf
Sorry but isn't don't work, the code generate a 0 byte file. Thank you

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 9:36 am
by Caronte3D
Simo_na wrote: Tue Jun 28, 2022 9:21 am Sorry but isn't don't work, the code generate a 0 byte file. Thank you
I can't reproduce that fault, it works well for me.

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 11:21 am
by blueb
Simo_na wrote: Tue Jun 28, 2022 9:21 am Sorry but isn't don't work, the code generate a 0 byte file. Thank you
Yes Simo_na, I also get a 0 byte file.

I'm using PB 6.0 (x64) on a Windows 10 Pro machine.

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 11:32 am
by Simo_na
blueb wrote: Tue Jun 28, 2022 11:21 am I'm using PB 6.0 (x64) on a Windows 10 Pro machine.
W10 Pro 21H2 here

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 12:13 pm
by blueb
Simo_na wrote: Tue Jun 28, 2022 11:32 am W10 Pro 21H2 here
Identical to mine. :D

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 12:18 pm
by Simo_na
i've try with Win 11 and PB6, nothing change... 0 size file
Intel Core I9 11900KF
32 GB DDR4

Re: Feature Request 'SaveMemory' to Disk Drive

Posted: Tue Jun 28, 2022 12:39 pm
by ChrisR
It also works for me on Windows 10 21H2 by allocating 1 Gb memory.

But if I allocate 2 Gb, In debug, it crashes on Line 8, WriteData : Invalid memory access.
I have 10Gb of free memory currently