Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - ptrtomem() copy from memory address to an object http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ptrtomem()          Copy from memory address to an object
------------------------------------------------------------------------------
 Declaration
   memory.hdr

 Syntax
   proc ptrtomem extern
   param value _POINTER pMem, ;
               untyped  xObject, ;
         value uint     uLength

 Arguments
   pMem is the source address.
   xObject is the destination memory object.
   uLength is the length of the copy operation.

 Return
   None.

 Description
   The procedure copies uLength bytes from the memory contents starting at
   pMem to the address of xObject. The procedure can be used, as
   an example, to copy the contents of arrays to some other place.

   Use this procedure with extreme care, as it may overwrite important
   memory areas if called with an invalid address, or an excess length.

 Example
   #define EXAMPLE_MEMORY
   #include example.hdr

   proc Test_ptrtomem
   vardef
      char        cSrc
      char        cDest
      ptr( byte ) pSrc
      ptr( byte ) pDest
   enddef
   cSrc := "Three ways of copying a string"
   
   // Copy string using string operator
   cDest := ""
   ? cDest
   cDest := cSrc
   ? cDest
   
   // Copy string using function calls
   cDest := ""
   ? cDest
   ptrtomem( addr( cSrc ), cDest, len( cSrc ) + 1 )
   ? cDest
   
   // Copy string using pointers
   pSrc := &cSrc
   pDest := &cDest
   *pDest := 0
   ? cDest
   do while *pSrc
      *pDest := *pSrc
      pSrc++
      pDest++
   enddo
   ? cDest
   endproc

   proc main
   Test_ptrtomem()
   endproc

See Also: memtoptr()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson