On 28 Apr., 10:40, James Kanze <james.ka...@gmail.com> wrote:
On Apr 26, 9:38 am, "Bo Persson" <b...@gmb.dk> wrote:
osama...@gmail.com wrote:
[...]
I am implementing a lockless queue, which I don't think
the std::queue<T*> provides.
You'd have to see the documentation for your implementation, but
by default, std::queue is lockless, since there are no locks (or
threads) in the standard. Most of the implementations I'm
familiar with do not use locks even in multithreaded
environments.
And it probably is the wrong level anyway.
[snip]
If the types are different, and the compiler is conform, he
probably will.
On the compiler I use, templates will most often share code for
objects of the same size, as the linker will merge identical code
blocks.
I certainly hope not. That wouldn't be conform. (I presume, of
course, that the compiler will only do so if the objects are
PODs as well. Otherwise, the code won't be identical.)
I believe you are wrong.
For example,
struct two
{
short x;
short y;
};
std::vector<int> v1;
std::vector<long> v2;
std::vector<two> v3;
will only generate one set of code in the resulting .exe file.
Despite the fact that the member functions of v1, v2 and v3 are
guaranteed to have different addresses?
None of the compilers I use do this (at least not to my
knowledge).
That must be because you do not use VC 8.0 (or 9.0). And I really do
not see any reason to disallow std::vector<int>:push_back to have an
adress that equals e.g. std::vector<unsigned>:push_back. How are you
going to detect that in the first place?
Like James says, he can take the address of the functions and compare.
Different objects must have different addresses, including functions.
translation units. The linker tries to fix this by only keeping one
copy of each identical code block. That this also merges code blocks
for different types of equal size, is by accident.
this. :-)