473,386 Members | 1,842 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,386 software developers and data experts.

porting non-malloc code to malloc

Hi,
I want to post some code which has defn like

struct AVPicture {
int *data[4];
int linesize[4];
}
the is noe recognised by matlab, so i need to port to some form like
struct AVPicture {
int **data;
int *linesize;
}

Now whatz the best way to go about this process

1. write a wrapper header, but how to initialize the constants ?? like
... **data to *data[]
2. rewrites the source .. [impossible]

-madan

Nov 14 '05 #1
3 1484
mi*********@gmail.com wrote:
Hi,
I want to post some code which has defn like

struct AVPicture {
int *data[4];
int linesize[4];
}
the is noe recognised by matlab, so i need to port to some form like
struct AVPicture {
int **data;
int *linesize;
}
Maybe it is just me but I cannot make much sense out of
this. Why do you want to post code but do not do it?
Matlab offers an interface for C code but this is a Matlab
thing, not a C thing.
What is the problem with the above structures?
That you have to pass only pointers to your data or that
you want to be able to size the arrays as you need them or ...?

Now whatz the best way to go about this process

1. write a wrapper header, but how to initialize the constants ?? like
.. **data to *data[]
What constants? Do you mean macros?
2. rewrites the source .. [impossible]


Please try to state your problem more clearly and provide
a minimal example which exhibits the erroneous behaviour or
shows the difference you need.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #2
Matlab has the ability to load MSVC compliant DLL's, atleast thatz what
they claim.

matlab has a function called loadlibary, which can can load my DLL
for ex: loadlibrary('mylib.dll','mylib.h')
where mylib.h is the interface header file.

the problem with matlab is that, it works perfectly laod the dll as
long as there are pointers to functions , and sized constants (ex. int
linesize[4]) ..

Now my problem, is that the DLL i have already has those sized
constants. I need to write a wrapper, which basically converts the
single or 2D pointers, to the corresponding formats.
for ex. the matlab interface needs int *linesize, but the DLL has int
linesize[4].

-madan

Nov 14 '05 #3
In article <11*********************@f14g2000cwb.googlegroups. com>,
<mi*********@gmail.com> wrote:
:Now my problem, is that the DLL i have already has those sized
:constants. I need to write a wrapper, which basically converts the
:single or 2D pointers, to the corresponding formats.
:for ex. the matlab interface needs int *linesize, but the DLL has int
:linesize[4].

If you were to pass an arbitrary structure into a C function, by
casting the pointer to void*, then there is no standard way for the
function to be able to figure out what the structure looks like
internally. (Some implimentations might have non-standard ways.) You
will thus not be able to write a C function which can be passed an
arbitrary structure and which will construct the appropriate new
structure.

Similarily, if you try to work it at the preprocessor level, you will
find that the preprocessor has no way to refer to items such as "the
first element of the named parameter". You thus will not be able to do
what you want by a preprocessor macro being passed an arbitrary
structure.

If you were willing to rewrite all your structure definitions, then you
could perhaps [in newer versions of C] write something like a
"DEFINE_STRUCTURE" macro that took as arguments all the pieces of the
structure, and which emitted both the regular 'struct' definition and
the modified definition you needed. Except that you want more than just
that -- you would also want to emit a pair of function that converted
between the two forms. I don't know if that is possible with a variable
number of arguments even in C99 [I haven't looked at what the C99
preprocessor is capable of.]
What I would suggest to you is that your problem would be most easily
solved outside the C program itself, by using some preprocessing
of your header files. As the preprocessing would be largely
textual, I would suggest that a program such as perl might be
easier to impliment this in than in pure C. The idea would be
to write a program (e.g., perl script) which read your header
files that define your structures, and emitted code that
defined the modified header and defines functions to do the
conversion. If you have lots of code, you could get fancier and
add a script that read through the code, figured out which
structures were referenced, and inserted #include statements
into the code to import the modified structure definitions
and conversion functions.
--
We don't need no side effect-ing
We don't need no scope control
No global variables for execution
Hey! Did you leave those args alone? -- decvax!utzoo!utcsrgv!roderick
Nov 14 '05 #4

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

Similar topics

7
by: Mark Hahn | last post by:
(I apologize in advance if this is not an appropriate posting) I have written a simple windows shareware app, EzPicMailer, in Python 2.3, wxPython 2.4.1, and PIL 1.1.4 that lets computer novices...
2
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more...
14
by: Wolfgang Keller | last post by:
Hello, as a non-developer I am currently participating in an industrial "research" project to develop a so-called "web application". This application serves at the same time as middleware to...
4
by: golu | last post by:
Has any body done the porting from oracle to sql server, what were the issues in porting the data bases? Also suggest some resources which can be helpful in the porting project TIA Golu
4
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
2
by: Theo Harlauch | last post by:
Hi, I'm quite sure if this newsgroup is suitable for my question but I'll give it a try. I'd like to port an application of mine which is currently just curses driven to a guish one. For now,...
2
by: rawCoder | last post by:
Hi all, I have an application in visual basic 6 which communicates with servers written in ANSI C++ using a C++ ( non COM ) dll by passig data through functions in UDT and receiving data back...
4
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the...
5
by: shobhah | last post by:
Hi, We have a complete succsssfully working product on 32bit sparc solaris machine for which compiler used is CC 5.8 Now we are migarting our product from 32 bit to 64bit sparc solaris machine....
47
by: =?Utf-8?B?ZW1hdmlzdQ==?= | last post by:
Dear guys, I'm in trouble having to port my project from C++Builder6 to VisualC++. Has anyone of you idea if there are any tools to help my doing this job? My current project is widely using VCL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.