Announcement

Collapse
No announcement yet.

Memory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Memory

    Hello,
    has someone a code for using memory ?
    i can't get it to run with GLOBALMEM ALLOC.
    H.Brill
    German User

  • #2
    As you have not shown your code, I'm guessing!

    You have to LOCK the global memory block to get a pointer to it. The handle is not a pointer.

    Comment


    • #3
      something like this?

      Code:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "win32api.inc"
      '#INCLUDE "hexdump.inc"
      FUNCTION PBMAIN () AS LONG
           LOCAL p AS BYTE PTR
           LOCAL hgmem, lresult AS DWORD
           LOCAL s AS STRING
           LOCAL pdw, pmem AS DWORD PTR
           
           s = STRING$(100,&H39)
           p = STRPTR(s)
           GLOBALMEM ALLOC 1000 TO hgmem
           ? "allocated" + STR$(hgmem),%MB_TASKMODAL
           GLOBALMEM LOCK hgmem TO pmem
           ? "locked" + STR$(pmem),%MB_TASKMODAL
           movememory @pmem, p, 100
           ? "moved",%MB_TASKMODAL
           'hexdump(@pmem, 100)
           GLOBALMEM UNLOCK hgmem TO lresult
           ? "unlocked",%MB_TASKMODAL
           IF lresult <> 0 THEN ? "error unlocking memory",%MB_TASKMODAL
           GLOBALMEM FREE hgmem TO lresult
           ? "freed",%MB_TASKMODAL
           IF lresult <> 0 THEN ? "error freeing memory",%MB_TASKMODAL
      END FUNCTION

      Comment


      • #4
        i have found the trick :

        Code:
        LOCAL mem, x, vhndl as LONG
        x = 1000
        GLOBALMEM ALLOC x TO vhndl
        mem = vhndl  
        ' and for free :
        GLOBALMEM FREE mem TO vhndl
        H.Brill
        German User

        Comment

        Working...
        X