Announcement

Collapse
No announcement yet.

Code on how to create a Ram Disk drive

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

  • #21
    Hi Steve,

    I noticed that you had allocated a memory of 1024*1024 bytes or 1 MB using the CreateMMF() function to create the MMF.
    How much can we increase the size of this MMF ? Can we have a 400 MB file ?


    I have just tested with 10240*10240 or 104 MB MMF and it still works!

    This is still less than 4 GB maximum which I saw for normal 32bit RAM disk.

    Comment


    • #22
      Tim,

      Make sure you use the #option largemem32 so that you have access at just under 2 gig and this will allow you to make memory mapped files close to 2 gig. Remember if you are using basic string that it needs as much memory as the string size to work with so a safe limit is about just under 1 gig. If you isolate the mapped file from basic string operations you can go bigger but it will be a test and see rather than just allocating that much. If you have enough available memory, go as big as you need but keep absolute limits in mind. you need 64 bit to handle much larger.


      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • #23
        Great Thanks to you, Steve now that these modules work beautifully will try to keep it below 500 MB

        Comment


        • #24
          Steve, after creating the memory mapped file using

          Code:
          zString = "Memory_Mapped_File.txt"
          pstring = VARPTR(zString)
          
          ' creates a 104MB MMF
          CreateMMF -1,pstring,10240*10240,VARPTR(hMMF),VARPTR(pMMF)

          then I tried using the below function to find the file "Memory_Mapped_File.txt"
          to see if I can find the file , but I couldn't find it at all ?




          Code:
          '==================================
          ' check if MMF file exist or not
          FUNCTION ChkMMFexist( szfilein AS STRINGZ * 64) AS LONG
          LOCAL w32dd AS win32_find_data
          LOCAL hsearch AS LONG
          
          ' check that we can find the file, and get its size if we can
          hsearch = findfirstfile (szfilein, w32dd)
          IF hsearch <> %invalid_handle_value_long THEN
          ' file exist
          FUNCTION = 1
          closehandle hsearch
          ELSE
          ' file does not exist
          FUNCTION = 0
          EXIT FUNCTION
          END IF
          
          END FUNCTION

          The question is that memory mapped files couldn't be search or located by using the normal file find API ?
          If this assumption is correct, then I think that memory mapped files are very well hidden and more secure then normal files?

          Comment


          • #25
            The only way that I could detect whether the memory mapped file actually exist is by using getlasterror as below

            Code:
             '  creates the MMF
                    LOCAL lasterror AS LONG
                    zString = "Memory_Mapped_File.txt"
                    pstring = VARPTR(zString)
                      CreateMMF -1,pstring,1024*1024,VARPTR(hMMF),VARPTR(pMMF)
                     lasterror = getlasterror
                     IF lasterror = %error_already_exists  THEN
                        ? " MMF already exist "
                     ELSE
                        ? " MMF does not exist "
                     END IF
            but this can be done only after the fact or after the CreateMMF function is carried out?

            Comment


            • #26
              Hello all , this is a DDT version of the Steve's codes to show MMF communication between 2 dialogs Main and Secondary,
              please add some comments to improve on it, thanks to all

              I'm still new to SDK so DDT may be of help to others who may need to understand the program better.
              I also attempt to use a huge 104MB MMF to test out my pc resources, which works fine

              The Main Dialog program

              Code:
              ' Main MMF.bas
              ' This is the main dialog to launch the MMF
              
              
               #COMPILE EXE
               #DIM ALL
              ' this is required for placement of large MMF
               #OPTION LARGEMEM32
              
              
               #INCLUDE "WIN32API.INC"
               #INCLUDE "MMFaid.inc"
              
              %IDC_BUTTON1  = 1001
              %IDC_BUTTON11 = 1011
              %IDC_BUTTON12 = 1012
              %IDC_TEXTBOX1 = 1013
              %IDC_Label    = 1021
              
              '===================
              FUNCTION PBMAIN()
                  DispMainDialog
              END FUNCTION
              
              
              
               '============================
               SUB DispMainDialog
                  LOCAL hDlg , dwTBStyle  AS DWORD
                  LOCAL  hFontEp   AS LONG
              
              
              
                  DIALOG NEW  %HWND_DESKTOP, "Main MMF Dialog", 70, 70, 320, 222, TO hDlg
                  DIALOG SET COLOR hDlg, -1, %RGB_LIGHTYELLOW
              
              
                   FONT NEW "Comic Sans MS", 10, 3, 0, 0, 0 TO hFontEp
              
              
                   CONTROL ADD LABEL, hDlg, %IDC_Label, _
                          "Enter some text here to write into the MMF", _
                          40, 15, 245, 11
                   CONTROL SET COLOR hDlg, %IDC_Label, %RGB_MEDIUMBLUE , -2
                   CONTROL SET FONT hDlg, %IDC_Label, hFontEp
              
              
                   dwTBStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %ES_LEFT OR _
                             %ES_MULTILINE OR %ES_AUTOVSCROLL  OR %ES_WANTRETURN OR _
                             %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                             %WS_EX_RIGHTSCROLLBAR
                  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "",   60, 29, 200, 60 ,dwTBStyle
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1,_
                           "Write the above text into MMF", 60, 105, 105,15
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON12, _
                           "Write a fix string into MMF and textbox ", 60, 135, 135,15
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON11, _
                         "Display MMF contents", 165, 185, 85,15
              
              
                  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Exit", 280, 200, 30, 15
              
                  DIALOG SHOW MODAL hDlg, CALL DlgProc
                  FONT END hFontEp
              
               END SUB
              
              
              
              '================================
              '  Main dialog callback
              CALLBACK FUNCTION DlgProc()
              
                ' for the MMF
                  LOCAL basSt  AS STRING
              
                  SELECT CASE AS LONG CB.MSG
                      CASE %WM_INITDIALOG
                          ' Initialization handler
                            '  creates the MMF
                            LOCAL lasterror AS LONG
                            LOCAL ptrMMFil AS DWORD
                            LOCAL MMFilnam AS STRINGZ * 512
                            MMFilnam = "Memory_Mapped_File.txt"
                            ptrMMFil = VARPTR(MMFilnam)
                        '   Create a huge 104 MB MMF
                            CreateMMF -1,ptrMMFil,10240*10240,VARPTR(hMMF),VARPTR(pMMF)
                    '        lasterror = getlasterror
                    '        if lasterror = %error_already_exists  then
                      '        good method to detect if MMF already exist
                     '         ? " MMF already exist "
                    '        else
                     '          ? " MMF does not exist "
                    '       end if
              
              
              
                      CASE %WM_COMMAND
                          SELECT CASE AS LONG CB.CTL
              
                                 CASE %WM_CLOSE
                                    ' perform cleanups before exit -- when close button is pressed
                                      CloseMMF pMMF,hMMF
              
              
              
                              CASE %IDC_BUTTON1
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                     CONTROL GET TEXT  CB.HNDL, %IDC_TEXTBOX1 TO basSt
                                     WriteMMF(basSt,pMMF)
                                  END IF
              
                               CASE %IDC_BUTTON11
                                  ' Display the MMF contents
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                       ' reads from MMF
                                       LOCAL mmsgSt AS STRING
                                       mmsgSt = ReadMMF(pMMF)
                                       MSGBOX mmsgSt,0," MMF contents"
                                  END IF
              
                                 CASE %IDC_BUTTON12
                                  ' Write a fix string into MMF and textbox
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                     basSt = "This is a test of writing to an MMF from Main dialog"
                                     CONTROL SET TEXT  CB.HNDL, %IDC_TEXTBOX1 , basSt
                                     WriteMMF(basSt,pMMF)
                                  END IF
              
              
              
                              CASE %IDCANCEL
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                      DIALOG END CB.HNDL, 0
                                  END IF
              
                          END SELECT
                  END SELECT
              END FUNCTION


              the Secondary dialog program
              Code:
              ' Sec MMF.bas
              ' This is the Secondary dialog to launch the MMF
              
              
               #COMPILE EXE
               #DIM ALL
              ' this is required for placement of large MMF
               #OPTION LARGEMEM32
              
              
               #INCLUDE "WIN32API.INC"
               #INCLUDE "MMFaid.inc"
              
              %IDC_BUTTON1  = 1001
              %IDC_BUTTON11 = 1011
              %IDC_BUTTON12 = 1012
              %IDC_TEXTBOX1 = 1013
              %IDC_Label    = 1021
              
              '===================
              FUNCTION PBMAIN()
                  DispSecDialog
              END FUNCTION
              
              
              
               '============================
               SUB DispSecDialog
                  LOCAL hDlg , dwTBStyle  AS DWORD
                  LOCAL hFontEp   AS LONG
              
              
                  DIALOG NEW  %HWND_DESKTOP, "Secondary MMF Dialog",_
                               370, 170, 320, 222, TO hDlg
                  DIALOG SET COLOR hDlg, -1, %RGB_AZURE
              
              
                  FONT NEW "Comic Sans MS", 10, 3, 0, 0, 0 TO hFontEp
                  CONTROL ADD LABEL, hDlg, %IDC_Label, _
                          "Enter some text here to write into the MMF", _
                          40, 15, 245, 11
                   CONTROL SET COLOR hDlg, %IDC_Label, %RGB_DARKGREEN , -2
                   CONTROL SET FONT hDlg, %IDC_Label, hFontEp
              
              
                  dwTBStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR %ES_LEFT OR _
                             %ES_MULTILINE OR %ES_AUTOVSCROLL  OR %ES_WANTRETURN OR _
                             %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                             %WS_EX_RIGHTSCROLLBAR
                  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "",   60, 29, 200, 60 ,dwTBStyle
              
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, _
                             "Write the above text into MMF", 60, 105, 105,15
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON12, _
                              "Write a fix string into MMF and textbox ", 60, 135, 135,15
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTTON11,_
                              "Display MMF contents", 165, 185, 85,15
              
              
                  CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Exit", 280, 200, 30, 15
              
                  DIALOG SHOW MODAL hDlg, CALL DlgProc
                  FONT END hFontEp
              
               END SUB
              
              
              
              '================================
              '  Main dialog callback
              CALLBACK FUNCTION DlgProc()
                ' for MMF
                  LOCAL mmsgSt AS STRING
                  LOCAL basSt AS STRING
              
                  SELECT CASE AS LONG CB.MSG
                      CASE %WM_INITDIALOG
                          ' Initialization handler
                            '  creates the MMF
                            LOCAL lasterror AS LONG
                            LOCAL ptrMMFil AS DWORD
                            LOCAL MMFilnam AS STRINGZ * 512
                            MMFilnam = "Memory_Mapped_File.txt"
                            ptrMMFil = VARPTR(MMFilnam)
                        '   Create a huge 104 MB MMF
                            CreateMMF -1,ptrMMFil,10240*10240,VARPTR(hMMF),VARPTR(pMMF)
                    '        lasterror = getlasterror
                    '        if lasterror = %error_already_exists  then
                      '        good method to detect if MMF already exist    <-----Secondary dialog will need this file detector
                     '         ? " MMF already exist "                       <----- if MMF doesn't exist need to exit
                    '        else                                                    for this secondary dialog
                     '          ? " MMF does not exist "
                    '       end if
              
              
              
                      CASE %WM_COMMAND
                          SELECT CASE AS LONG CB.CTL
              
                                 CASE %WM_CLOSE
                                    ' perform cleanups before exit -- when close button is pressed
                                      CloseMMF pMMF,hMMF
              
              
              
                              CASE %IDC_BUTTON1
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                     CONTROL GET TEXT  CB.HNDL, %IDC_TEXTBOX1 TO basSt
                                     WriteMMF(basSt,pMMF)
                                  END IF
              
                               CASE %IDC_BUTTON11
                                  ' Display the MMF contents
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                       ' reads from MMF
                                       mmsgSt = ReadMMF(pMMF)
                                       MSGBOX mmsgSt,0," MMF contents"
                                  END IF
              
                                 CASE %IDC_BUTTON12
                                  ' Write a fix string into MMF and textbox
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                     basSt = "This is a test of writing to an MMF from secondary dialog"
                                     CONTROL SET TEXT  CB.HNDL, %IDC_TEXTBOX1 , basSt
                                     WriteMMF(basSt,pMMF)
                                  END IF
              
              
              
                              CASE %IDCANCEL
                                  IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                      DIALOG END CB.HNDL, 0
                                  END IF
              
                          END SELECT
                  END SELECT
              END FUNCTION

              the include MMFAid.inc all Steve's work except added trailing blanks into WriteMMF()
              to blank off old data inside the MMF
              Code:
              ' MMFaid.inc
              ' support routines for MMF  Sep 13 2020
              'https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/799576-code-on-how-to-create-a-ram-disk-drive?p=799673#post799673
              ' Thanks to Steve
              
              
                  GLOBAL hMMF     AS DWORD                ' memory mapped file handle
                  GLOBAL pMMF     AS DWORD                ' pointer to mapped file memory
              
              
              
              
              
              
              '=======================================
               ' CreateMMF proc lpName:DWORD,bcnt:DWORD,lphndl:DWORD,lpMemFile:DWORD
              '  1. hFile  An open file handle created with CreateFile
              '  2. lpName The zero terminates string that names the file
              '  3. bcnt   The size of the required memory mapped file in BYTES.
              '  4. lphndl Pointer to DWORD variable to receive the address of the memory mapped file handle.
              '  5. lpMem  Pointer toDWORD variable to receive the start address of the memory mapped file.
              
              '  The lphndl and lpMemFile have the file handle and start address written to them when the
              '  procedure returns. There is no return value.
              
              FUNCTION CreateMMF( _
                                  BYVAL hFile AS DWORD, _
                                  BYVAL lpName AS DWORD, _
                                  BYVAL bcnt AS DWORD, _
                                  BYVAL lphndl AS DWORD, _
                                  BYVAL lpMem AS DWORD _
                                ) AS DWORD
              
                  LOCAL hMMF AS DWORD
              
                  hMMF = CreateFileMapping(hFile, _           ' open file handle
                                BYVAL %NULL, _                ' unused security attribute
                                %PAGE_READWRITE, _            ' read write access to memory
                                0, _                          ' unused high DWORD
                                bcnt, _                       ' required size in BYTEs
                                BYVAL lpName)                 ' set file object name here
                  PREFIX "!"
                    mov ecx, lphndl                           ' store address of variable in ECX
                    mov [ecx], eax                            ' write MMF handle to variable
                  END PREFIX
              
                  MapViewOfFile(hMMF, _
                                %FILE_MAP_WRITE, _
                                0,0,0)
                  PREFIX "!"
                    mov ecx, lpMem                            ' store address of variable in ECX
                    mov [ecx], eax                            ' write start address to variable
                  END PREFIX
              
              END FUNCTION
              
              
              '====================================
               ' CloseMMF proc lpMem:DWORD,hMMF:DWORD
              '  1. lpMem The start address OF the MEMORY mapped file
              '     returned by the CreateMMF procedure.
              '  2. hMMF  The HANDLE returned by the CreateMMF procedure.
              FUNCTION CloseMMF( _
                                 BYVAL lpMem AS DWORD, _
                                 BYVAL hMMF AS DWORD _
                               ) AS DWORD
              
                  UnmapViewOfFile lpMem
                  CloseHandle hMMF
              
              END FUNCTION
              
              
              
              '=====================================
              ' writes into the MMF a given string gbasSt
              FUNCTION WriteMMF(gbasSt AS STRING,BYVAL mmf AS DWORD) AS DWORD
                  LOCAL pbas AS DWORD
                  LOCAL lbas AS DWORD
               '  Need to blank off all the previous data in the MMF
                ' by adding a huge blank string at its back
                  gbasSt = gbasSt + SPACE$(1000)
                  pbas = STRPTR(gbasSt)
                  lbas = LEN(gbasSt)
                  bcopy pbas,mmf,lbas
              
              END FUNCTION
              
              
              '=============================
              ' Reads from the MMF a string outpSt
              FUNCTION ReadMMF(BYVAL mmf AS DWORD) AS STRING
              
                  LOCAL stln AS DWORD
                  LOCAL ptxt AS DWORD
                  LOCAL outpSt AS STRING
                  stln = slen(mmf)
                  outpSt = SPACE$(stln)
                  ptxt = STRPTR(outpSt)
                  bcopy mmf,ptxt,stln
              
                  FUNCTION = outpSt
              
              END FUNCTION
              
              
              '=================================
              FUNCTION bcopy(BYVAL Vsource AS DWORD,BYVAL Vdestination AS DWORD,_
                      BYVAL blen AS DWORD) AS DWORD
              
                  PREFIX "!"
              
                  mov esi, Vsource
                  mov edi, Vdestination
                  mov ecx, blen
                  rep movsb
              
                  END PREFIX
              
              END FUNCTION
              
              
              '=======================================
              FUNCTION slen(BYVAL sptr AS DWORD) AS DWORD
              
                  PREFIX "!"
              
                  mov eax, sptr
                  sub eax, 1
                lbl:
                  add eax, 1
                  cmp BYTE PTR [eax], 0
                  jne lbl
              
                  sub eax, sptr
                  mov FUNCTION, eax
              
                  END PREFIX
              
              END FUNCTION

              Comment


              • #27
                Also in the MMFaid.inc above, I'm not sure what the functions Slen() and Bcopy() do?
                any comments are appreciated here. I guess that Bcopy meant Binary Copy ?

                Comment


                • #28
                  Tim,

                  As long as its string data you are reading and writing, you don't need to add the trailing blanks, the "slen" algo is a standard byte scanner that finds the terminating ascii zero which gets the string length. The algo "bcopy" (bytes copy) copies the number of bytes from the MMF back to the basic string of that length.

                  When I get around to it I will do a matched pair that will handle binary data as well. Basic string is well suited for this task as it uses a string length 4 bytes below so the length is already known, I just have to work out a tidy way to pass this data to and from the MMF.
                  hutch at movsd dot com
                  The MASM Forum

                  www.masm32.com

                  Comment


                  • #29
                    Thanks Steve,
                    The basis of adding trailing blanks in WriteMMF() is because of :
                    I noticed that when the 2 modules ( Main dialog and Secondary dialog in post #26) communicate with the memory mapped file MMF , If the length of the
                    old string in the MMF exceeds the new string ( to be written into MMF) then part of the Old string will linger on and remains in the MMF.

                    That's why I added 1000 trailing blank spaces whenever we write in the new string into the MMF , this will then override or clear off the old string, you can test
                    it out yourself by commenting out the below line in WriteMMF()


                    gbasSt = gbasSt + SPACE$(1000)

                    Comment


                    • #30
                      Hi Tim,

                      I have done the two new versions of read and write and they will now handle both text and binary data in both direction via normal basic dynamic string. The two assembler algorithms are no longer needed as I have combined the copy procedure into the two Read and Write functions. There are a couple of choices, I have put all 4 MMF functions into a SLL based library for my own use and you are welcome to it as the function act like normal intrinsics. Alternately I can put the functions into source code.
                      hutch at movsd dot com
                      The MASM Forum

                      www.masm32.com

                      Comment


                      • #31
                        lso, Michael the purpose of this Memory Mapped file is to share a small file on a temporary basis. data such as initial parameters such as data filename, printer settings etc
                        I wonder how secure this file would be whether it is not intercepted by another party or not ?
                        I do that in one of my applications. I don't need no stinkin; RAM disk, either.

                        I create a memory MMF using GUITEXT$(GUID()) as its name, then I pass that name to another app on a command-line which is ShellExecuteEx'd. I have to have a unique name because I can have several of these objects "alive" at the same time.

                        I signal the calling app with a user-defined event and then the caller may close its handle to that memory object.. which then can be deleted by the using program when it's done with it.by closing its handle. (although I could just let it die by closing the one open handle to it, I consider that sloppy and lazy programming)

                        So... instead of a "RAM-disk problem," you really have an "interprocess communications challenge." Sure sounds cooler to me!

                        MCM
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #32
                          Thanks Steve, would appreciate if you could provide the 4 MMF functions in source code please. As SLL is a restrictive "black box" kind of object
                          and that may not be portable to other languages if PB does not work out at a future date?


                          Thanks Michael,on the usage of a unique file name for MMF, I have a question for you as the below code was used to check if the MMF exist
                          and that I found that it does not work.

                          Does it means that we cannot use a simple API like findfirstfile() to search for these MMF?

                          If findfirstfile() couldn't find it, I w'd be happy to use MMF as it w'd be more secure than other normal files?

                          Code:
                          '==================================
                          ' check if MMF file exist or not
                          FUNCTION ChkMMFexist( szfilein AS STRINGZ * 64) AS LONG
                          LOCAL w32dd AS win32_find_data
                          LOCAL hsearch AS LONG
                          
                          ' check that we can find the file, and get its size if we can
                          hsearch = findfirstfile (szfilein, w32dd)
                          IF hsearch <> %invalid_handle_value_long THEN
                          ' file exist
                          FUNCTION = 1
                          closehandle hsearch
                          ELSE
                          ' file does not exist
                          FUNCTION = 0
                          EXIT FUNCTION
                          END IF
                          
                          END FUNCTION

                          Comment


                          • #33
                            Tim,

                            With the file set to -1, it uses the system paging file so there is never a file on disk.

                            Here are the two algos. Be very careful modifying either of them.
                            Code:
                            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                            
                            FUNCTION ReadMMF(ByVal mmf as DWORD) as STRING
                            
                                #REGISTER NONE
                            
                                LOCAL ptxt as DWORD
                                LOCAL tlen as DWORD
                            
                                PREFIX "!"
                                  mov eax, mmf                              ' load mmf address
                                  mov eax, [eax]                            ' write its value to eax
                                  mov tlen, eax                             ' store the length in 1st 4 bytes into variable
                                END PREFIX
                            
                                outp$ = space$(tlen)                        ' allocate a buffer of "tlen"
                                ptxt  = StrPtr(outp$)                       ' get the buffer pointer
                            
                                PREFIX "!"
                                  add mmf, 4                                ' add 4 to get to start of text
                                  mov esi, mmf                              ' load the mmf address + 4
                                  mov edi, ptxt                             ' load the destination (mmf) address
                                  mov ecx, tlen                             ' set the count to copy
                                  rep movsb                                 ' copy "tlen" bytes from mmf to basic string
                                END PREFIX
                            
                                FUNCTION = outp$                            ' return the string
                            
                            END FUNCTION
                            
                            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                            
                            FUNCTION WriteMMF(bas$,ByVal mmf as DWORD) as DWORD
                            
                                #REGISTER NONE
                            
                                LOCAL pbas as DWORD
                                LOCAL lbas as DWORD
                            
                                pbas = StrPtr(bas$)
                                lbas = len(bas$)
                            
                                PREFIX "!"
                                  mov eax, mmf                              ' load the mmf address into eax
                                  mov ecx, lbas                             ' load the string length into ecx
                                  mov [eax], ecx                            ' write string length to 1st 4 bytes of mmf
                            
                                  add mmf, 4                                ' add 4 to mmf to get where to write the data
                                  mov esi, pbas                             ' load basic string address
                                  mov edi, mmf                              ' load the destination (mmf) address
                                  mov ecx, lbas                             ' set the count to copy
                                  rep movsb                                 ' copy basic string to MMF
                                END PREFIX
                            
                            END FUNCTION
                            
                            ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                            hutch at movsd dot com
                            The MASM Forum

                            www.masm32.com

                            Comment


                            • #34
                              Thank you Sir Steve, also found that there is no need to add trailing blanks in WriteMMF() as discussed in post#29
                              when added the above routines into the program listed in post#26

                              Comment


                              • #35
                                Tim,
                                Already in Source Code. COM Communication Relay between Apps

                                Comment


                                • #36
                                  Thank you Sir Jim, I have forgotten that completely as I was doing other stuff .....

                                  Comment


                                  • #37
                                    Looks like you found another solution.
                                    I actually have a great ramdisk, but really don't need it much.
                                    When running 32-bit Windows it is more useful.
                                    A nice thing about a professional ramdisk like this is the ability to save image of the ram disk so it doesn't need to be refilled at startup from the source.
                                    This means the ramdisk and the original source can be different.
                                    Also can create hybrid disks allowing only so much memory for ramdisk and if ramdisk is filled disk space is used.

                                    https://www.romexsoftware.com/en-us/...file-disk.html
                                    How long is an idea? Write it down.

                                    Comment


                                    • #38
                                      Hi Tim,

                                      here

                                      https://www.sixsigmain.it/blog_jsl.html

                                      (videos named stress test .. 4 to 7)

                                      a real example of MMF code + COM code to manage different Clients (mixing 32/64 host/clients)

                                      j2Friend (the bridge) is made using only pbwin10 (sdk) pure code.

                                      MMF To Client messages :
                                      - private : processed by a single Client only,
                                      - public : processed by all active Clients,
                                      - common : as public for active Clients with same class only.


                                      Look to Steve (Hutchesson), Patrice (Terrier) and Josè (Roca) posts (to whom my thanks go for his immense work) and you will find the solution to your problem.

                                      Franco

                                      Comment


                                      • #39
                                        I posted the name of the ramdisk I use, ImDISK that comes at the right price and is a very flexible tool. If you set it up the right way it saves the content to a directory when the computer shuts down and restores it on startup but the other trick is that you can set it up to only use as much memory as the data you have on the ramdisk. With my own setup I have allocated 16 gig to the ramdisk but only have a couple of gig sitting on it and the use I have is things that I use regularly like a web browser and a number of other apps and tools.

                                        With the browser run from ramdisk, when you start it you get the "blink" effect, blink and its up and running.

                                        https://sourceforge.net/projects/imdisk-toolkit/
                                        hutch at movsd dot com
                                        The MASM Forum

                                        www.masm32.com

                                        Comment


                                        • #40
                                          Thank you everyone, I found that Steve's MMF routines works really well and I was able to write and read into 5 MMF simultaneously using 3 host programs.
                                          One of the MMF is fairly large at 104 MB and it works like clockwork! Great thanks to Steve's invaluable routines.
                                          I will be testing a MMF random file read and write and see its performance.

                                          When I search the internet, it seems that MMF in C# programs has an added advantage in that it also restrict access to MMFs with security rights and permission,
                                          I 'm wondering if these access rights can be applied to PB MMFs ?

                                          Comment

                                          Working...
                                          X