• 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Need help in memory manipulation
If you allocate memory and request any memory type, the OS will allocate to the highest priority memory automatically. This is normally your fastest RAM, so just allocate the memory you need with the type set to public. For Blitz commands, you can use

InitBank 1, 32768, 0

where 1 is the bank number for easy reference, 32768 is the number of bytes to allocate and 0 is the type of memory (0=any, 1=public, 2=chip). This memory should be in your fast RAM unless there isn't a large enough chunk free.

If you want to load a file directly into memory, you can use the LoadBank command. This automatically initialises the memory so you don't need the InitBank command above. Use it like this:

LoadBank 1, "Work:Myfile.dat", 0

Where 1 is the bank number, "Work:Myfile.dat" is the file you want to load into memory, and 0 is the memory type (any in this case).

After either of these commands, use the Bank() function to get the address of the bank.

MyAddr.l = Bank(1)

Where the 1 is the bank number used above. Be sure to check that MyAddr is >0, just in case it wasn't allocated for any reason. You *will* crash the machine if you try to use unallocated memory!

Once that's in place you can use the OS calls to copy memory between addresses as you need. The Copymem_(src.l,dest.l,size.l) call will copy size.l bytes from the src.l address to the dest.l address. Again, BE VERY CAREFUL to ensure you've properly allocated both source and destination memory or you will most likely crash!

The CopymemQuick_() call is similar but faster. The only difference is that you can only use long-aligned address and copy sizes.

Finally, free up all memory you allocate when your program ends. If you used InitBank, you can use FreeBank 1 to free it again.

Nachrichten in diesem Thema

Gehe zu:

Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste