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

Trouble with heap after call of DLL method

I am having a serious trouble with my pointers in a programm that uses
dll and was hoping that somebody in this group could help me:

I export my DLL classes with declspec(dllexport) and link against them
using the lib-file. I do not use anything but stuff included in the C++
standard libraries (like iostream) so far.

In my calling application I first do

class __declspec(dllimport) Image {
public:
Image();
....

};

and afterwards I do
double * values = new double[9];
double values[0] = 0.0;
....
double values[8] = 0.0;

cout << "DEBUG: values is at address " << values << endl;
Image im();
cout << "DEBUG: deleting at memory address " << values << endl;
delete [] values;

The empty image constructor does nothing, not even initializing the
member variables with standard values. I tried to resimulate the
ever-reoccuring problem under a minimal environment and an in my
opinion an empty member constructor is such.

Now I fail to delete values. The output of the program is:

DEBUG: values is at address 003814C0
DEBUG: deleting at memory address 00381400

Obviously I am either overwriting the pointer to the array or I having
some other heap problem - which is really driving me crazy, since I
can't find the reason for it.
When I am calling a static (exported) function such as
Image::printHelloWorld(); the problem doesn't occur.

If I am initializing values from stack (double values[9]); values[0] is
overwritten after the DLL method call...

Can anybody tell me, what I seem to be missing here?

Thanks in advance

May 11 '06 #1
2 1801
bellerophon wrote:
I am having a serious trouble with my pointers in a programm that uses
dll and was hoping that somebody in this group could help me:

I export my DLL classes with declspec(dllexport) and link against them
using the lib-file. I do not use anything but stuff included in the C++
standard libraries (like iostream) so far.

In my calling application I first do

class __declspec(dllimport) Image {
public:
Image();
...

};

and afterwards I do
double * values = new double[9];
double values[0] = 0.0;
...
double values[8] = 0.0;

cout << "DEBUG: values is at address " << values << endl;
Image im();
This does not invoke the constructor; it declares a function named "im"
returning an Image and taking no parameters. Thus, it should not invoke
your DLL at all.
cout << "DEBUG: deleting at memory address " << values << endl;
delete [] values;

The empty image constructor does nothing, not even initializing the
member variables with standard values. I tried to resimulate the
ever-reoccuring problem under a minimal environment and an in my
opinion an empty member constructor is such.

Now I fail to delete values. The output of the program is:

DEBUG: values is at address 003814C0
DEBUG: deleting at memory address 00381400

Obviously I am either overwriting the pointer to the array or I having
some other heap problem - which is really driving me crazy, since I
can't find the reason for it.
When I am calling a static (exported) function such as
Image::printHelloWorld(); the problem doesn't occur.

If I am initializing values from stack (double values[9]); values[0] is
overwritten after the DLL method call...

Can anybody tell me, what I seem to be missing here?

Thanks in advance


Show us a minimal but *complete* sample that demonstrates your problem.
If it is a C++ *language* issue, we'll try to help you. If it is a DLL
issue, you'll have to ask the Microsoft folks, as DLLs are off-topic in
this group. For what is on-topic and for some potential groups you
could pursue this in if it's not a language issue, see this FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

May 11 '06 #2
>
This does not invoke the constructor; it declares a function named "im"
returning an Image and taking no parameters. Thus, it should not invoke
your DLL at all.

The brackets () slipped in, I'm sorry (I'm still *this* used to Java) -
in my program I have just used Image im;
Show us a minimal but *complete* sample that demonstrates your problem.
If it is a C++ *language* issue, we'll try to help you. If it is a DLL
issue, you'll have to ask the Microsoft folks, as DLLs are off-topic in
this group. For what is on-topic and for some potential groups you
could pursue this in if it's not a language issue, see this FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M


Well, probably it's a DLL issue. I'm sorry for posting this off-topic
but I didn't find the groups mentioned in the FAQ in the first place...
Thanks for your help anyways!

May 11 '06 #3

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

Similar topics

14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
2
by: Riley DeWiley | last post by:
I have a program which must call into third party code that might do a wild write (I have been getting ASSERTs and access violations in debug code when I am freeing pointers after a call into that...
3
by: nahur | last post by:
why do you need a heap and a stack why not all memory called a heap or call it a stack what is the purpose of having a heap and a stack
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
24
by: arcticool | last post by:
I had an interview today and I got destroyed :( The question was why have a stack and a heap? I could answer all the practical stuff like value types live on the stack, enums are on the stack, as...
16
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area...
1
by: Chris Mullins | last post by:
We've been using the SSLStream class found in System.Net.Security to build a giant Sockets server that provides TLS encryption at the channel leve. Before .Net 2.0, we used an open-source...
0
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
3
by: emer.kurbegovic | last post by:
how can i get heap memory of a windows process with C#? For example, I would like to see the value of the heap memory allocated for my "java.exe" process. thanks in advance.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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

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.