Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4323994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:04:24+00:00 2026-05-21T09:04:24+00:00

I want to share array data between two applications. In my mind, first program

  • 0

I want to share array data between two applications. In my mind, first program create the array and the second program can read the array from already allocated memory area. The array is not a dynamic array.

I found a way to share pointer using OpenFileMapping and MapViewOfFile. I have no luck to implement array sharing and I think i don’t want to use IPC method yet.

Is it possible to plan a scheme like this (sharing array)? My purpose is to minimize memory usage and reading data quickly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:04:25+00:00Added an answer on May 21, 2026 at 9:04 am

    Scratched my head thinking of what a short-but-complete example of sharing memory between two applications might be. The only option is a console application, GUI applications require a minimum of 3 files (DPR + PAS + DFM). So I cooked up a small example where one integers array is shared using a memory mapped file (backed by the page file so I don’t need to have a phisical file on disk for this to work). The console application responds to 3 commands:

    • EXIT
    • SET NUM VALUE Changes the value at index NUM in the array to VALUE
    • DUMP NUM displays the value in the array at index NUM
    • DUMP ALL displays the whole array

    Of course, the command processing code takes up about 80% of the whole application. To test this compile the following console application, find the executable and start it twice. Go to the first window and enter:

    SET 1 100
    SET 2 50
    

    Go to the second console and enter this:

    DUMP 1
    DUMP 2
    DUMP 3
    SET 1 150
    

    Go to the first console and enter this:

    DUMP 1
    

    There you have it, you’ve just witnessed sharing memory between two applications.

    program Project2;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils, Windows, Classes;
    
    type
      TSharedArray = array[0..10] of Integer;
      PSharedArray = ^TSharedArray;
    
    var
      hFileMapping: THandle; // Mapping handle obtained using CreateFileMapping
      SharedArray: PSharedArray; // Pointer to the shared array
      cmd, s: string;
      num, value, i: Integer;
      L_CMD: TStringList;
    
    function ReadNextCommand: string;
    begin
      WriteLn('Please enter command (one of EXIT, SET NUM VALUE, DUMP NUM, DUMP ALL)');
      WriteLn;
      ReadLn(Result);
    end;
    
    begin
      try
        hFileMapping := CreateFileMapping(0, nil, PAGE_READWRITE, 0, SizeOf(TSharedArray), '{C616DDE6-23E2-425C-B871-9E0DA54D96DF}');
        if hFileMapping = 0 then
          RaiseLastOSError
        else
          try
            SharedArray := MapViewOfFile(hFileMapping, FILE_MAP_READ or FILE_MAP_WRITE, 0, 0, SizeOf(TSharedArray));
            if SharedArray = nil then
              RaiseLastOSError
            else
              try
                WriteLn('Connected to the shared view of the file.');
    
                cmd := ReadNextCommand;
                while UpperCase(cmd) <> 'EXIT' do
                begin
                  L_CMD := TStringList.Create;
                  try
                    L_CMD.DelimitedText := cmd;
                    for i:=0 to L_CMD.Count-1 do
                      L_CMD[i] := UpperCase(L_CMD[i]);
    
                    if (L_CMD.Count = 2) and (L_CMD[0] = 'DUMP') and TryStrToInt(L_CMD[1], num) then
                      WriteLn('SharedArray[', num, ']=', SharedArray^[num])
                    else if (L_CMD.Count = 2) and (L_CMD[0] = 'DUMP') and (L_CMD[1] = 'ALL') then
                      begin
                        for i:= Low(SharedArray^) to High(SharedArray^) do
                          WriteLn('SharedArray[', i, ']=', SharedArray^[i]);
                      end
                    else if (L_CMD.Count = 3) and (L_CMD[0] = 'SET') and TryStrToInt(L_CMD[1], num) and TryStrToInt(L_CMD[2], value) then
                      begin
                        SharedArray^[num] := Value;
                        WriteLn('SharedArray[', num, ']=', SharedArray^[num]);
                      end
                    else
                       WriteLn('Error processing command: ' + cmd);
    
                  finally L_CMD.Free;
                  end;
    
                  // Requst next command
                  cmd := ReadNextCommand;
                end;
    
    
              finally UnmapViewOfFile(SharedArray);
              end;
          finally CloseHandle(hFileMapping);
          end;
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to share an Array which all classes can get and change data
I have a PHP page and I want to share some data between pages
I want to share an object between my servlets and my webservice (JAX-WS) by
We want to share user validation configuration between a Java validation class (for sanity
Say I have the following interface that I want to share between my server
If all tables I want to delete from have the column gamer_id can i
say I want to load an array of short from global memory to shared
I want to share some memory between different processes running a DLL. Therefore i
I want to share the customize message from my android device to facebook. To
I've a small project that I want to share with a few others on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.