Feature Request 'SaveMemory' to Disk Drive

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Feature Request 'SaveMemory' to Disk Drive

Post 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 :)
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Feature Request 'SaveMemory' to Disk Drive

Post by jacdelad »

If you put the parameter Size last you can make it optional and make it even easier. Leaving it could trigger MemorySize().
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
Last edited by Simo_na on Sun Jun 26, 2022 10:54 pm, edited 1 time in total.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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.
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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.
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post 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
User avatar
blueb
Addict
Addict
Posts: 1041
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Feature Request 'SaveMemory' to Disk Drive

Post by blueb »

Simo_na wrote: Tue Jun 28, 2022 11:32 am W10 Pro 21H2 here
Identical to mine. :D
- It was too lonely at the top.

System : PB 6.10 Beta 9 (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Feature Request 'SaveMemory' to Disk Drive

Post by Simo_na »

i've try with Win 11 and PB6, nothing change... 0 size file
Intel Core I9 11900KF
32 GB DDR4
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Feature Request 'SaveMemory' to Disk Drive

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