lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Regarding C++...

Value-based semantics (e.g., std::vector) encourage the attitude that objects can be copied as easily as integers. But unless your value actually is implemented using COW this isn't the case. Move semantics in C++ 11 help reduce the number of cases where a copy actually gets made but they also add another level of complexity to the language.

And if you are implementing COW, now you need to go back and figure out how to manage that. The answer is probably a shared (reference counted) pointer.

If you just use references, you need to be aware that they are potentially only valid for a limited period of time. If you take the address of an object, that's basically a pointer just waiting to go bad.

Try using an object from multiple threads in C++ and figure out when it is safe to dispose of it without reference counting (or something like it).

My general point about C++ is that it provides tools that can be used to provide precise and reasonably efficient memory management but it also provides plenty of ways to overuse memory and to create unsafe situations and neither of the latter necessarily looks like bad code on the surface. (cf the remark that the problem with LISP is that efficient code and inefficient code look the same)

Mark