how to hide my implementation of template library
#1
Posted 18 November 2005 - 02:30 PM
as you know, all implementation of templated class should be included in the headers
or it can't to be properly linked to user application
so what can i do if i want to hide these function bodies?
#2
Posted 18 November 2005 - 03:04 PM
-
Currently working on: the 3D engine for Tomb Raider.
#3
Posted 18 November 2005 - 03:11 PM
template <class T> class TemplClass {
// ...
}
// use this when building the DLL on windows
template class __declspec(dllexport) TemplClass<int>;
template class __declspec(dllexport) TemplClass<float>;
template class __declspec(dllexport) TemplClass<double>;
// etc...
// use this when using the DLL on windows
extern template class __declspec(dllimport) TemplClass<int>;
extern template class __declspec(dllimport) TemplClass<float>;
extern template class __declspec(dllimport) TemplClass<double>;
// etc...
You can use macros to handle the export/declspec stuff.
#4
Posted 18 November 2005 - 03:11 PM
Second, I think it is highly unlikely that you came up with any of these algorithms yourself, so isn't it ironic that you feel that you have something proprietary to hide??
Third, if its templated it's probably so general that it isn't optimized for any PC architecture.
Lastly, if your code is of any value at all, it probably won't be understandable by anyone even with commented source code.
My point is that even if you released the code, I doubt anyone will even use it. Welcome to reality.
#5
Posted 18 November 2005 - 03:13 PM
-
Currently working on: the 3D engine for Tomb Raider.
#7
Posted 18 November 2005 - 04:47 PM
I find the negative tone to your post rather disheartening, given some of the great advice people give here without trying to bring others down. As such, let me play devil's advocate to the items you mention, in the hopes of giving people reasons why to help rather than be snide.
CobraLionz said:
1.- Noone said he was going to release this library, and perhaps he's doing it just to learn.
CobraLionz said:
2.- Implementation hiding is not necessarily for security of your code. It can be for other reasons, most notably to defeat unnecessary rebuilds if your interface doesn't change yet your implementation does (this is my chief argument for implementation hiding).
CobraLionz said:
3.- Not necessarily true. You can still do ifdef based on platform inside of templated functions, and it will thereby be specialized for that particular platform. You can even get crazier using Boost's support for conditionals based on types and such (albeit I don't know much on that subject), so you can get a great degree of granularity on this.
CobraLionz said:
4.- This is simply an unfounded negative opinion.
CobraLionz said:
5.- Noone said he's releasing it. And coding for the sake of learning is probalby one of the best ventures possible.
I'm sorry if I seem snarky in my replies, but the one thing I've noticed in this forum is that everyone from the most junior person to the most senior is able to ask questions without fear of being mocked. This question is quite valid, and while I knew the outcome of this, I would've loved to be proven wrong.
Keep askin' questions feel_energetic, and good luck with your library. :)
#8
Posted 18 November 2005 - 06:13 PM
#9
Posted 18 November 2005 - 11:51 PM
Max
#10
Posted 19 November 2005 - 02:49 PM
.oisyn said:
thanks for your reply:)
I also cared about 'export'
when searching the standard for help
what i want to know about this keyword is
"if it can't do any help to the templated functions,
is the declarator really implemented? and is it really useful?"
#11
Posted 19 November 2005 - 03:27 PM
monjardin said:
code
...
You can use macros to handle the export/declspec stuff.
yes this was the way how i managed it first:)
it runs well with both dll and template , it's nice for most cases
but i also found something not so good
all different types used to instantiated(spell wrong?) the template class should be declared in the exported DLL, this forbids the user of the DLL to use their ADT as template parameter
furthermore, if i use an int as template paramter of class Vector(for example) to set the vector size at compile-time, i should write many declarations with different number, each of them with a whole specialized implementation.
after that, I realized DLL and template have different design goal, DLL is based on the run-time resolving, and template is based on compile-time computation. To combine them is not a good idea. Then i removed the DLLs and came here for help:)
#12
Posted 19 November 2005 - 03:56 PM
CobraLionz said:
Second, I think it is highly unlikely that you came up with any of these algorithms yourself, so isn't it ironic that you feel that you have something proprietary to hide??
Third, if its templated it's probably so general that it isn't optimized for any PC architecture.
Lastly, if your code is of any value at all, it probably won't be understandable by anyone even with commented source code.
My point is that even if you released the code, I doubt anyone will even use it. Welcome to reality.
Thanks for these words
I'm sorry that I didn't mention that I create this subject is only for technical feasibility, not for finding a way to get my source locked
actually, the math library is used in a vision library to help my further reseach on computer vision
i'm also learning template metaprogramming and maybe this is a good chance to practise it
#13
Posted 20 November 2005 - 06:11 PM
feel_energetic said:
I also cared about 'export'
when searching the standard for help
what i want to know about this keyword is
"if it can't do any help to the templated functions,
is the declarator really implemented? and is it really useful?"
That very same question is asked by many of the compiler vendors, and most of them answered it with "no, it isn't very useful, it's certainly not worth all the time and effort to implement it". Due to the nature of templates, you can't compile them as a seperate piece of code, like you can with seperate sourcefiles and libraries. It can only be compiled at the moment of instantiation, and it even needs the context at the point of the template definition itself (for example, if a templated function calls some other overloaded function, all the overloaded functions declared after the template function shouldn't be considered in the list of possible overloads).
So even when using export, the "library" containing the exported code is imported and "recompiled" on instantiation. Therefore your library either contains the actual sourcecode, or some literal translation of it. And just like java bytecode, which is a near 1:1 translation of the sourcecode, such an exported library can easily be decompiled back into C++ sourcecode. And the compiler which implement export basically require you to keep your implementation sourcefiles as the library for the "exported" code. And since you can just as easily seperate your implementation from the class definition and include the implementation from your header, I don't really why compiler vendors should implement the export keyword, or even why the export keyword even exists in the standard.
-
Currently working on: the 3D engine for Tomb Raider.
#14
Posted 23 November 2005 - 04:13 AM
i've got it
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












