Development reference: Difference between revisions
No edit summary |
No edit summary |
||
Line 71: | Line 71: | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
! c++ | ! c++ in-memory storage of "major" objects | ||
|- | |- | ||
| | | | ||
OBSERVATION ONE | OBSERVATION ONE | ||
QObjects cannot normally be copied | Consider An Important Qt Design: QObjects cannot normally be copied | ||
their copy constructors and assignment operators are private | |||
why? A Qt Object... | why? A Qt Object... | ||
might have a unique QObject::objectName(). If we copy a Qt Object, what name should we give the copy? | might have a unique QObject::objectName(). If we copy a Qt Object, what name should we give the copy? | ||
Line 91: | Line 88: | ||
OBSERVATION TWO | OBSERVATION TWO | ||
if you have a vector of objects, you often want to track them individually | if you have a vector of objects, you often want to track them individually outside the vector | ||
if you use a vector of pointers, you can move the object around much more cheaply, and not worry about costly large vector reallocations | if you use a vector of pointers, you can move the object around much more cheaply, and not worry about costly large vector reallocations | ||
a vector of objects (not pointers) only makes sense if the number of objects is initially known and does not change over time | |||
OBSERVATION THREE | OBSERVATION THREE | ||
STL | STL vectors can store your pointers, iterate thru them, etc. | ||
for a vector of any substantial size, you want to keep objects sorted so you can find them quickly | for a vector of any substantial size, you want to keep objects sorted so you can find them quickly | ||
that's what my sorted_vector class is for | that's what my sorted_vector class is for; it simply bolts vector together with sort calls and a b_sorted status | ||
following STL practices, to get sorting, you have to provide operator< for whatever is in your vector | following STL practices, to get sorting, you have to provide operator< for whatever is in your vector | ||
BUT... you are not allowed to do operator<(const MyObjectPtr* right) because it would require a reference to a pointer which is not allowed | BUT... you are not allowed to do operator<(const MyObjectPtr* right) because it would require a reference to a pointer which is not allowed | ||
BUT... you can provide a FUNCTOR to do the job, then provide it when sorting/searching | BUT... you can provide a FUNCTOR to do the job, then provide it when sorting/searching | ||
a functor is basically a structure with a bool operator()(const MyObjectPtr* left, const MyObjectPtr* right) | a functor is basically a structure with a bool operator()(const MyObjectPtr* left, const MyObjectPtr* right) | ||
OBSERVATION FOUR | |||
unordered_set works even better when combining frequent CRUD with frequent lookups | |||
|} | |} | ||
Revision as of 15:08, 6 January 2014
Expandc++11 containers |
---|
Expandc++11 example for large groups of objects with frequent crud AND search |
---|
Expandc++11 example for large groups of objects with infrequent crud and frequent search |
---|
Expandc++11 example for unordered_map using custom object as key |
---|
Expandc++11 example for multiple unordered_set indexes into one group of objects |
---|
Expandc++11 for loop using lambda |
---|
Expandc++ in-memory storage of "major" objects |
---|
Expandc++ stl reverse iterator skeleton |
---|
c++ stl reading a binary file |
---|
Expandc/c++ gdb debugging |
---|
ExpandCreate a portable command line C project in Visual Studio |
---|
ExpandCreate a portable C++ project in Visual Studio |
---|
Expandphp debugging |
---|
Expandjava eclipse project layout format |
---|
ExpandSQL Server 2008+ proper upsert using MERGE |
---|
Expandgit recreate repo |
---|
Expandbash chmod dirs |
---|
Web Services |
---|
Firefox Addon development |
---|
Expandmediawiki collapsible skeleton |
---|
Expandmediawiki collapsible example |
---|