Article View: borland.public.cppbuilder.nativeapi
Article #4625Re: how can I share a dynamic list of objects in a dll
From: Andrue Cope [TeamB]
Date: Tue, 03 Jan 2006 12:17
Date: Tue, 03 Jan 2006 12:17
69 lines
3677 bytes
3677 bytes
David L wrote:
> typedef std::vector <TMyObject*> V_MyObject_LST;
> typedef std::vector <TMyObject*>::iterator V_MyObject_Iterator;
>
> is it possible to share a dynamic list (size between 5000000 and
> 8000000) of these objects in a dll for 3 .exe that need same datas ?
I'd be a little loathe to do that. Such data types are language
specific and even compiler specific. Accessing them through shared
memory would pretty much rely on the executable code of each DLL/client
being generated by the same compiler. I also imagine it would put a
horrible burden on you and other developers to locate and manipulate
the data correctly.
One the of the main benefits of DLLs is that they can be language and
compiler agnostic. As soon as a DLL exports (explicity through the API
or implictly through shared memory) anything beyond simple types that
benefit is lost. In the case of shared memory I think you are also
relying on the clients to understand and respect the layout of complex
structurs in memory. It's bad enough having to do that for yourself but
expecting/trusting other people to do it scares me :)
Unless performance is absolutely, 100% critical I would always far
rather use access functions. By that I mean you export iteration
functions like this:
// DLL code
int Object_ListBegin()
{
return 0;
}
int Object_ListEnd()
{
return OBJECTLIST_END_MARKER;
}
void Object_ListIncrement( int * ObjectHandle )
{
if( ( *ObjectHandle!=Object_ListEnd() )&&
( *ObjectHandle+1<V_MyObject_LST.size() ) )
++( *ObjectHandle );
else
*ObjectHandle=ObjectListEnd();
}
// Example method call:
double Object_GetData1( int Handle )
{
return V_MyObject_Lst[ Handle ]->GetData1();
}
Of course you'd probably want to add more validation for the above code
but I hope it conveys the idea.
BTW:Are you sure you want to populate your std::vector with /pointers/
to objects? It is usually better to populate the std::vector with
object instances so that the std::vector can take full ownership and
save you having to worry about correct allocation/deallocation. The
example class you've posted here will store quite nicely in a
std::vector. Of course not all classes will but it's always possible to
create a copy ctor and assignment operators. The additional work for
such classes is usually outwheighed by the advantage of not having to
worry about ownership semantics.
--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<43ba6aca$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder.xsnews.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<XnF97407D8CF14A9davidluuexanecom@207.105.83.66>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,214e5f2a6f9443ae X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope [TeamB]" <no.spam@not.a.valid.address> Subject: Re: how can I share a dynamic list of objects in a dll Newsgroups: borland.public.cppbuilder.nativeapi References: <XnF97407D8CF14A9davidluuexanecom@207.105.83.66> Date: Tue, 3 Jan 2006 12:17:34 +0000 User-Agent: XanaNews/1.17.6.6 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <43ba6aca$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1136290506 217.207.223.34 (3 Jan 2006 04:15:06 -0700) Lines: 69 X-Authenticated-User: acope Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news.glorb.com!newsgate.cistron.nl!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder.xsnews.nl!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail