473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

binary input and memory address passing

Hello,

I can open, read, and convert data to a numeric (double) array from a
binary file using

nc = #something given
nr = #something given
f_o=open('junk.bin','rb')
x=reshape(array('d',f_o.read()),(nr,nc))

Is there a way in python that gives better performance? These commands
take three to 4 times longer than loading the data into an array in (for
example) octave.

Also, is there a way to pass the address of a block of memory, and then
access the data located there (pass by reference and let the python
program know what data type to use)?

My situation: I have two programs that can not communicate directly, but
I can get memory addresses for any data in my programs. I currently save
to a file, then load the data from file into my other program. Clearly
it would be much faster if I could access the block of memory directly
rather than making a copy.

Any suggestions greatly appreciated.

Cheers,

Eric Carlson
Dec 13 '06 #1
2 1681
Eric Carlson wrote:
Hello,

I can open, read, and convert data to a numeric (double) array from a
binary file using

nc = #something given
nr = #something given
f_o=open('junk.bin','rb')
x=reshape(array('d',f_o.read()),(nr,nc))

Is there a way in python that gives better performance? These commands
take three to 4 times longer than loading the data into an array in (for
example) octave.

Also, is there a way to pass the address of a block of memory, and then
access the data located there (pass by reference and let the python
program know what data type to use)?

My situation: I have two programs that can not communicate directly, but
I can get memory addresses for any data in my programs. I currently save
to a file, then load the data from file into my other program. Clearly
it would be much faster if I could access the block of memory directly
rather than making a copy.

Any suggestions greatly appreciated.
You might look over my (admittedly old)
http://members.dsl-only.net/~daniels/Block.html
It only has a Python 2.2 and 2.3 installer, but the sources are there
for you to compile (in which case you might toss a package back to me,
and I'll put it up). If you look it over and have questions, let me
know.

--Scott David Daniels
sc***********@acm.org
Dec 13 '06 #2

Thanks Dennis and Scott for both responses. Since Dennis has slam dunked
my notion of sharing memory addresses (my ignorance in computing is
pretty much unbounded), I guess I will need to continue on with sharing
through files.

Opening up and loading the binary info into a string variable is very
fast. The process bogs when changing the representation to float. So it
appears that Scott's Block module might do what I need.

My original:

nc = #something given
nr = #something given
f_o=open('junk.bin','rb')
x=reshape(array('d',f_o.read()),(nr,nc))

gives me any array with nr rows and nc columns. Using Block I think I
would use:

f_o=open('junk.bin','rb')
x = View('d', Block(f_o.read()))

Okay, so now how can I use this? Is this like an array type so that

x = reshape(x,(nr,nc))

makes sense?

Regards,
Eric
Dec 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
1
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
9
by: Arnold | last post by:
I need to read a binary file and store it into a buffer in memory (system has large amount of RAM, 2GB+) then pass it to a function. The function accepts input as 32 bit unsigned longs (DWORD). I...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
10
by: Fabuloussites | last post by:
I'm considering deploying an application that will us an IP address locaiton database provided by Ip2location.com... http://www.ip2location.net/ip2location-dotnet-component.aspx their .net...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
5
by: erfan | last post by:
vc++6.0,winxp. I use this code to see the memory address and the real value`s address below: #include<stdio.h> int main() { int a=22; int *p; int i; p=&a;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.