Can Blender share MemoryBlocks with other progams?

Hi there,

I’d like to let Blender’s - Python-scripts share memory with an other program.

The other program is written in Delphi (i.e. Pascal).
I used Delphy for quite a long time so I already know how to use a part of memory with Delphi.
My problem is Python (I m just using it for a few weeks and had my first go with it in Blender).

Does anyone know how to read and write to and from memoryblocks in Python?
And maybe tell me what problems I could encounter?
What further basic hints would you give a Python noob?

Greeting to You

i am interrested too
python is limited by his low speed…

Hey Alex,
Sorry for this late reply, but I have been experimenting a lot last days. Started my job again after hollydays, so I have less time to spare next months.

What I have been doing so far is:
Make a .CSV-file that contains some data.
Let a Python-function in Blender make a MemoryMap of his File.
Read data from that memorymap and close the file again.

My goal is to make e memorymap of the file in Python (e.a. Blender) and a memorymap of the same (part of) the file in Delphi.
In this way reading from- and writing to the file is verry quick and both progams can share data.
By the way, this is not what I was looking for, but the next best solution I could think of.

any suggestions?

Greetings to you


hi jbal,

if i understand, blender and your program share data by this file.
I was thinking about it, but it could be slow if there are many data.

i am not an expert in sharing memory between programs but i will search for too.

we can also use the file to just share the location of data in the memory block :slight_smile:

keep it up mate :smiley:

Hi Alex

I agree, in case of large amounts of data this could be to slow, but its a start anyway.

The best whould be to share physcal memmory but at this moment I realy don’t know how to do that.

By the way: Are you used to program? If so what language(s) are you used to[C?
Greetings to you


i can program in C, java, turbo pascal ( :smiley: ), python … (licence informatique cursus LMD and i will begin the master)

i find something in C (POSIX), i will try this later.
the most important for now is the python side of the code.

also it should be good to know the object’s structure.


For programing I am a self-made-man, Did some educational software; but thats a long time ago
(turbo-pascal under DOS, it was about he first mouse-driven sofware for education).
Years later I learnt to use Delphi. I do make some software for friends.
I think with respect to programming you are the better part of us.

About object structure:
I am not sure about that. In the long term
I am trying to make a RTS game where two armies meet on a battlefield and fight it out.
(there will be need of a AI too!!)
So I just started whith a simpel structure of block-symbols for Regiments.
These are top down related to a: ArmyCommander, CorpsCommnder, DivisionCommnder, BrigadeCommander
(All being live-objects on the battle-field)
The Objects will hold a lot of data (= properties), at this moment they just hold a name
(the relation to the rest of the army and their position is in the .CSV-file)
This weekend I plan to put one army on the battle-field, just to see things in Blender

I am still not sure of the overall structure, so I keep all of it simple and very flexible

Euh … please keep in mind I am not in a hurry, I like to sort things out (I like puzzling) and to do thing good.
My priority is livelike battle actions and not polished graphics.
(In the long term I do like to have good graphics)

I would appreciate your help, maybe a project for the two of us?
Or maybe more people?
(I wonder how many Blenderers are working on a RTS-game).

Greetings to you,
Have a nice weekend


for your game, it’s depnd what you want.
if the IA will be like total war games, it should be easy to do with python and the fluidity shoudn’t be affected.

for exemple: you can considere 50 characters like army, and so represent the army like empty. All 50 soldiers will calculate their position with this empty.

if like me, you want more, python could be a problem, that’s why i need to use external program to calculate what i want.

i suggest you to learn python, it’s very easy :wink:

I am not shure about all of that, but I know I want the chracters to react like a real army would
(fore instance take advantage of terrain by it self. Take decission to fight or retreat by it self,
In Total War you mostly have to give very specific orders to each regiment, that is not what I want )

About characters: I know i 'd like at least:
2 Armies x 3 corps x 3 divisions x 3 brigades x 3 regiments = 162 characters
and this is only infantry!.

Total War is the game I like the best at this moment,
but what I was thinking about is something like ‘Take Command 2nd Manassas’.
I played it a lot. I even tried to mod it.

I am learning Python at this moment and learning how to use it with the game engine.
Phython is easy I agree (although I think it is less structured than Pascal).

I wonder what you are up to with Blender. . . . I’d like to know


By the way, did you see this post of me

it’s a big project for you i think.
i developpe my own game and i need many character, and there is a very low frame rate !
i disable the physic engine and write all i need in python, and it’s not suffisant…

your IA will be extremly heavy for python.

ok find i think i have a way for my problem.
i will create my own DLL and add it by python script.
i have to test the frame rate.

you can also do your own DLL in delphi i think

I just installed a package in my Delphi-package.
It is called Py4D (obvious = Python for Delphy),
Looks like it gives me (some) control over memory-usage of Python.

I will try and test it the next week.

Keep it up !!!
and keep me posted!!

Greetings to you


if i understand, blender and your program share data by this file.
I was thinking about it, but it could be slow if there are many data.
I’ve done this type of thing before where two programs share data using a file system. Personally, on my computer, I’ve been able to send 100 variables between two programs at about 30 fps (not really slow, but it’s not really fast either).

Another method is to use C++ and use the “WriteToProcessMemory()” function. This possibly could be the fastest way to send data between two programs, but it’s not necessary stable (due to the fact that your working with unmanaged code). If you’d like some source code, just ask.

There is another way by “echoing” commands between two programs, but I haven’t played with it much… You might want to look into that (but then again, echoing requires C++).

Hey C-106 Delta,

Sorry for this late reaction, I was busy doing something realy different the last week.
Thanks for thinking with us. I use Pascal (eg Delphi) so C++ is no option at this moment.
Maybe Alex can use your hints.
Euh… what exactly do you mean by echoing, is this the same as sending (windows-)messages from one application to the other?

Hey Alex,
I made a very simple .ddl in Delphi and made Python load it.
The dll holds a few very simple functions just for testing.
My primary goal is to let Python use these functions, but this proves rather difficult for me.
I am trying to use the ctypes-module of Python, Gues I have to do lots of study there first.

Do you have any reading suggestions or some tutorial(s)
I already found these:



i have done many test with ctypes+DLL © and my result is:
ctypes copy and convert parameters to send to DLL.
so in very heavy function (very !!! ) you gain awesome result

bug if like me, you need little function (but with many call) the gain of the DLL just compensate the low speed of the ctypes module.

ctypes tut :

i think ctypes is not good for games. :frowning:
and i never use C++ :frowning: :frowning:

Hi Alex,

Seems ctypes is a dead end (and euh; sorry my mistake: what language are you using?).

I just found something interesting:
If you make a memorymap of a file in Python (using mmap) and give it a TagName,
any program can access the mapped data using that TagName (I just did using Delphi).
Obviously Python can read/write the data, but so can the other program.
These programs can thus exchange data by reading from- and writing to the memorymap.
Whats more: You don’t have to do time consuming writing/reading to the actual file.
I have to dig into this some more, will keep you posted.

Greetings to You :yes::yes::yes:


hey Jbal !
sorry if i take long time without posting, i didn’t have time :slight_smile:

i could be interresting to test mmap, if you already test it, call me !

however, another solution could appear, in my university, we study sharing memory in C. We just need to know how to do in python to link this.

i use C language for his speed :smiley:

Nice to see you are still around,

I just found a little non-Blender program (written in Pascal eg Delphi) that opens a memmoryblock,
this block will have a name so other programs can get access to this memoryblock to.
I changed it a bit to suite my needs.
Then I tried a simple script in Blender using the mmap.mmap(…) procedure to read the content of
the memoryblock.
And . . . . . Yes this worked.
So it is possible to send data from the outside world to your BlendeGE-world.

Now C and Pascal (Delphi) are, I think, closely related, so I suppoos this could be done in C too.

Then I tried to let Phyton make a memmoryblock and tried to acces it with a little program,
but this did not work (yet).

Got interessted?
Just tell me and I will post these programs on my webspace (I am out of time now)

Greetings to you


of course i am interrested :smiley:

Sorry it took so long for me to post my results, but I have been very
busy these day’s.

Warning: The programs are in their very early stages, so very crude programmed.
You will have to pollish them a lot.

Ok here they are:

The .zip-file contains the following important files:
Further a lot of files important if you like to see how thing are
implemented using Delphi.
The most important ones are the .pas-files (and the .dpr-files)
(This should be at least good hint to show you how you can
do thing using C).

To realy use all of this you should have:

  • Python installed,
  • preferrably use Pyscripter (free software) to run your .py’s in

If you want to change the .exe’s

  • delhpi installed (I use delphi6-personall edition wich was free at Borland
    some time ago)

How to us all of this:
Unpack the zip-file

Start the script
Start the MapMemSender.exe
Type some input in MemMemSender.exe
Type some input in en type <enter>
ReadMemMap will print the input of MapMemSender in the console-window.
(it is a very cruel procedure but it shows how you can send data from
one program to the other)

Start MapMem_Reaceaver.exe

Type some input in
This input should show up in the window of MapMem_Reaceaver.exe

I hope this works for you (I am not shure about the Zip-file, did zip and sending foor the first time ever)

Have fun with it,

Have a nice weekend