Is the following code thread safe when using boost shared_ptr.
Thanks!
class CResource
{
xxxxxx
}
class CResourceBase
{
CResourceBase()
{
m_pMutex = new CMutex;
}
~CResourceBase()
{
ASSERT(m_pMutex != NULL);
delete m_pMutex;
m_pMutex = NULL;
}
private:
CMutex *m_pMutex;
public:
void SetResource(shared_ptr<CResource> res)
{
CS...
Dynamic bitset
I have a use case where i need to populate
boost::dynamic_bitset<unsigned char> , from a std::string buffer.
Can you suggest as to how to go about this. So I need to come up with a function
void populateBitSet (std::string &buffer,
boost::dynamic_bitset<unsigned char> & bitMap) {
//populate bitMap ...
Map type from STL have next type:
std::map< Key, Data, Compare, Alloc >
As one of template parameters we could pass Compare predicate, why map accept this predicate as template parameter and not as object in constructor?
It could has more flexible interface with something like boost::function< bool, const T&, const T& > in constr...
I just performed Allocation Profiling about how many objects of each type are in my application. I am using boost::shared_ptr extensively.
I found a large number of sp_counted_impl_p objects allocated, each occupying 16 bytes. How many of sp_counted_impl_p objects can be expect per shared_ptr? Does someone have an idea?
...
What are some ways you can shoot yourself in the foot when using boost::shared_ptr? In other words, what pitfalls do I have to avoid when I use boost::shared_ptr?
...
I just started writing a small application in C++ using Visual Studio C++ 2008 Express. I installed the Boost Library using the windows installer. While compiling the program i get the following error :
Compiling...
stdafx.cpp
Compiling...
websave.cpp
GoogleAuthenticate.cpp
Generating Code...
Compiling manifest to resources...
Microsof...
I ran across enable_shared_from_this while reading the Boost.Asio examples and after reading the documentation I am still lost for how this should correctly be used. Can someone please give me an example and/or and explanation of when using this class makes sense.
...
std::string charBuff = "11010";
dbitset = boost::dynamic_bitset<unsigned char> (charBuff);
for (boost::dynamic_bitset<>::size_type i = 0; i < dbitset.size(); ++i) {
std::cout << dbitset[i];
}
It prints from the LSB to MSB. Output: 01011.
What should I do to so that bitset is printed correctly. I can reverse the character buffer ...
Hi,
using boost::graph with bundled properties. I want to be able to run searches using a variety of different possible edge weighting schemes. I'd like to not create an additional class for the bundled properties if possible, and pass in different weight maps depending on the type of search without creating a new graph or modifying all...
Does anyone know why the following generates an error on VC9?
class Elem;
class ElemVec : public vector<Elem>
{
public:
void foo();
};
void ElemVec::foo()
{
BOOST_FOREACH(Elem& elem, *this)
{
// Do something with elem
}
return;
}
The error I get is:
error C2355: 'this' : can only be referenced ins...
This one is for Boost experts. Are there any gotchas or details that the programmer needs to be aware of before he goes in and replaces all his old C/C++ style loops with the lean-and-mean-looking BOOST_FOREACH?
(This question is partly derived from here.)
...
The spate of questions regarding BOOST_FOREACH prompts me to ask users of the Boost library what (if anything) they are doing to prepare their code for portability to the proposed new C++ standard (aka C++0x). For example, do you write code like this if you use shared_ptr:
#ifdef CPPOX
#include <memory>
#else
#include "boost/shared_ptr....
Trying to learn asio, and I'm following the examples from the website.
Why is io_service needed and what does it do exactly? Why do I need to send it to almost every other functions while performing asynchronous operations, why can't it "create" itself after the first "binding".
...
When should I use asynchronous operations in boost::asio instead of synchronous operations in seperate threads?
...
Learning boost, and compiled their daytime server client example. Since I cant use port 13 that is in the example I only changed the port numbers in the server and client example. Server runs fine, but the client doesnt connect it seems, and no error is given.
Input data for the client is "127.0.0.1".
Server:
#include <ctime>
#include...
On my system, expat is located at
/usr/include/expat.h
/usr/include/expat_external.h
/usr/lib/libexpat.1.5.0.dylib
/usr/lib/libexpat.1.dylib
/usr/lib/libexpat.dylib
/usr/lib/libexpat.la
So I export the required variables for boost to build graphml
export EXPAT_INCLUDE=/usr/include
export EXPAT_LIBPATH=/usr/lib
then I run (where ...
I am using the Windows Driver Kit (WinDDK 6001.18001) to build my userspace application rather than Visual Studio 2005. I am taking this approach because we also have to build driver components, so I'd prefer to have a single build environment to build everything. Microsoft itself uses this approach for several products.
This was workin...
Can I use the Boost MPI to send files to other computers? My worry is that it is optimized for very small messages and not larger (I need to send 700 MB or more in one go). The reason is that I will probably use mpi for other parts of the program anyway so I thought it would be a pretty clean solution to not mix and match.
Has it been ...
Hello,
This question is a matter of style, since you can always write a for loop or something similar; however, is there a less obtrusive STL or BOOST equivalent to writing:
for (container<type>::iterator iter = cointainer.begin();
iter != cointainer.end();
iter++)
iter->func();
?
Something like (imagined) this:
call_for...
In the boost examples in the documentation, tcp:iostream is used to very simply send streams over the network. In other examples write() is used to write data to the socket instead with a bit more code involved.
What is the difference between those 2 methods? Pros and cons? Is there something else that should be used instead ?
...