473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with Templates with Shared libraries

AH
I have two functions in my shared library which are declared as
follows:

void setName(const std::string& str);
std::vector<std::string> getInfo();

Since the code is compiled and in shared library. Every thing is great
if the customer of my shared library is using the same compiler
version (and same STL version). I am wondering if the customer changes
their compiler version (or STL version) which may have same interface
for all the standard containers, but different implementations and
sizes; will it still work with my shared library?

Here's an example:
The first function I mentioned above takes a const std::string as an
argument. The compiler I used to build my library (say for example)
defines the std::string something like this (I've omitted the
interface and namespace for simplicity)

template<typename T>
class basic_string
{
T* buffer;
size_t size;
public:
// public interface for std::string goes here
};

typedef basic_string<char> string; // string I used in my first
function
Now say the customer is using an updated version of the same compiler
or some other compiler which defines the std::string by adding an
additional private variable 'count' for reference counting as follows:

template<typename T>
class basic_string
{
T* buffer;
size_t size;
unsigned long* count;
public:
// public interface for std::string goes here
};

Problem:

As you can see the customer passes the new string to my function which
has different size. The function I wrote originally expected a
std::string of a smaller size. Will this break my shared library???

Same thing is also can be said about the second function which returns
a vector of strings, but container returned might be different as what
compiler expects it to be if they are of different sizes.

What I am getting at is that is it a bad idea to use standard
containers in the interface for shared libararies? Since the standard
containers are Templated and not compiled when used by the user of a
shared library.

I hope you understand the problem. Any response will be greatly
appreciated.

Thank you,

Adnan
Jul 19 '05 #1
1 4386
AH wrote:
I have two functions in my shared library which are declared as
follows:

void setName(const std::string& str);
std::vector<std::string> getInfo();

Since the code is compiled and in shared library. Every thing is great
if the customer of my shared library is using the same compiler
version (and same STL version). I am wondering if the customer changes
their compiler version (or STL version) which may have same interface
for all the standard containers, but different implementations and
sizes; will it still work with my shared library?

Here's an example:
The first function I mentioned above takes a const std::string as an
argument. The compiler I used to build my library (say for example)
defines the std::string something like this (I've omitted the
interface and namespace for simplicity)

template<typename T>
class basic_string
{
T* buffer;
size_t size;
public:
// public interface for std::string goes here
};

typedef basic_string<char> string; // string I used in my first
function
Now say the customer is using an updated version of the same compiler
or some other compiler which defines the std::string by adding an
additional private variable 'count' for reference counting as follows:

template<typename T>
class basic_string
{
T* buffer;
size_t size;
unsigned long* count;
public:
// public interface for std::string goes here
};

Problem:

As you can see the customer passes the new string to my function which
has different size. The function I wrote originally expected a
std::string of a smaller size. Will this break my shared library???

Same thing is also can be said about the second function which returns
a vector of strings, but container returned might be different as what
compiler expects it to be if they are of different sizes.

What I am getting at is that is it a bad idea to use standard
containers in the interface for shared libararies? Since the standard
containers are Templated and not compiled when used by the user of a
shared library.

I hope you understand the problem. Any response will be greatly
appreciated.

Thank you,

Adnan

You will have the same problem with any user defined types. If you are
passing user defined types from/to the client (user of the shared
library), the client needs to know the size of the user defined type. So
if you change the implementation of the user defined type in the shared
library, it will cause problems in the client.
To get over this problem, instead of using user defined types for
communication between library and client , use interfaces . Also to
create objects in the shared library use class factory pattern.
Hope this helps.

Jul 19 '05 #2

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

Similar topics

0
by: Phil | last post by:
I realize this is the php group, but I have a question that recurses back to my php install. My objective is a pure 64 bit shared object installation of php 5.0 on UltraSparc Solaris 9 compiled...
3
by: Rickard Lind | last post by:
Is there any way to build the python executable statically and still be able to load modules built as shared libraries? I'm trying to run python scripts on a stripped down FreeBSD (4.9) machine...
13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
3
by: Alan Krueger | last post by:
Greetings, I've been able to cache Transformer objects in a Tomcat-based servlet application to avoid unnecessary Transformer rebuilding, except for certain ones on certain machines. I'm...
15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
1
by: Leslaw Bieniasz | last post by:
Cracow, 15.09.2004 Hi, I am writing a big C++ project using BCB 4.0. The project consists of several dlls and exes. Each of the dll is composed of several units (that is cpp files with...
5
by: Christian Christmann | last post by:
Hi, I want to implement an graph using templates. In my header file I define the templates node and edge: template <class NODE> class GNode { NODE *info; public: GraphNode();
0
by: ZR | last post by:
I am writing two applications which needs to (among other things) communicate through network, so one of them is a client and the other one is a server. I have used asynchronous socket examples...
5
by: David T. Ashley | last post by:
I've occasionally had trouble compiling and linking programs that use shared libraries. That never made a lot of sense to me, because I thought the operating system went hunting for the symbols...
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...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.