473,405 Members | 2,261 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,405 software developers and data experts.

delete objects created inside a dll

I am working on windows and create a dll. In side the dll, there is
something like

class B;
class A{
public:
B* GetB(){
B* pB = ...
return B;
}
};

Now the user use my dll:

A a;
B* pB = a.GetB();
....
delete pB;

There is a problem here. Since pB is allocated inside the dll. It
should be delete inside the dll too. But when the user call delete pB,
he is deleting it outsite the dll. How can I handle this?

Thanks,

qk
Jul 19 '05 #1
2 4536
<qu******@yahoo.com> wrote in message
news:ea**************************@posting.google.c om...
I am working on windows and create a dll. In side the dll, there is
something like

class B;
class A{
public:
B* GetB(){
B* pB = ...
return B;
}
};

Now the user use my dll:

A a;
B* pB = a.GetB();
...
delete pB;

There is a problem here. Since pB is allocated inside the dll. It
should be delete inside the dll too.


Are you sure? Or just guessing? I'm not sure, and I
would not guess.

If I needed to know, I'd ask in a Windows programming
group, e.g. comp.os.ms-windows.programmer32, or perhaps
visit www.msdn.microsoft.com where all things Windows-y
are documented and explained.

Here we only discuss the ISO standard C++ language,
which has no such thing as a 'DLL'.

Information about the nature and topic of newsgroup comp.lang.c++:
http://www.slack.net/~shiva/welcome.txt

-Mike
Jul 19 '05 #2
qu******@yahoo.com wrote in news:ead1f717.0309281504.1bfcb399
@posting.google.com:
I am working on windows and create a dll. In side the dll, there is
something like

class B;
class A{
public:
B* GetB(){
B* pB = ...
return B;
}
};

Now the user use my dll:

A a;
B* pB = a.GetB();
...
delete pB;

There is a problem here. Since pB is allocated inside the dll. It
should be delete inside the dll too. But when the user call delete pB,
he is deleting it outsite the dll. How can I handle this?

This is a hack but Standard conforming hack, add operator new and
operator delete to your defenition of B that way all invocations of
new and delete will use whatever code the dll would use for new and
delete.

<example omit="platform-dependant-dll-cruft">
class B
{
//...
public:
void *operator new ( unsigned sz );
void operator delete ( void *p );
};

// in a TU compiled into your dll

void *B::operator new ( unsigned sz )
{
return ::operator new ( sz );
}
void B::operator delete ( void *p )
{
::operator delete ( p );
}
</example>

There are other platform dependant ways off doing what you want, they
may be more effecient, you should ask about those elsewhere eg:

news://comp.os.ms-windows.programmer.win32

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 19 '05 #3

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

Similar topics

6
by: Bryan Martin | last post by:
I have a object that is created in a seperate domain which needs to be passed back to the parent class. Because this object is created in a seperate domain if I try to pass the object back to the...
52
by: Newsnet Customer | last post by:
Hi, Statement 1: "A dynamically created local object will call it's destructor method when it goes out of scope when a procedure returms" Agree. Statement 2: "A dynamically created object...
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
13
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I am using VS2005. I created a Windows Appication project. Inside the Server Explorer, I created a new SQLExpress database, and then created a new table. I added the rows, making my first row an...
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.