This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Coding style
Ali Karademir edited this page Nov 30, 2017
·
12 revisions
-
auto
keyword is an exception, it's well supported in gcc 4.9
- doing this allows us to port the code to other GC based language easily
- define destructor only when having compiling issue with undefined type (forward-declared only). in this case, define destructor in cc file and use empty function body
- the
ref_
type is based on boost:intrusive_ptr -
ref_
type is a smart pointer that's designed for performance but not thread safety - anything touching one
ref_
must run in same strand, unless:- when object is created in one strand/thread and send to other strand at once, the original strand completely forget about the instance
- in unit test, when knowing at a certain time all code are idle and nothing will read/write the
ref_
StorageBucket& SimpleStorage::get_bucket(const std::string& name) {
return *(new SimpleStorageBucket(_io_service));
}
instead do this
std::unique_ptr<StorageBucket> SimpleStorage::get_bucket(const std::string& name) {
return std::unique_ptr<StorageBucket>(new SimpleStorageBucket(_io_service));
- //write virtual deconstructor as default if at least one virtual function defined in that class. //otherwise it causes "new delete mismatch" issue virtual ~StorageBucket() = default;
- //if a class has some properties that shares the same ref_ of the parent class, always create that class with "make_ref_" //for example, Session has two properties called _ack_stream and ping_stream which shares the parent Session object. auto s3 = make_ref(config, "hello"); //never do this: Session s(config, "hello"); //or Session* s2 = new Session(config, "hello");
- //implement destroy_impl functions for the classes inherited from "EnableRef" //and call destroy() for deleting these objects. Do not wait for destructor.