SQLite – UPSERT *not* INSERT or REPLACE

Assuming three columns in the table: ID, NAME, ROLE BAD: This will insert or replace all columns with new values for ID=1: BAD: This will insert or replace 2 of the columns… the NAME column will be set to NULL or the default value: GOOD: Use SQLite On conflict clause UPSERT support in SQLite! UPSERT syntax was added to … Read more

When is it a good idea to use strdup (vs malloc / strcpy)

Which one is better? strdup(s); itself does not create a problem when allocation failures (calling code still needs to handle a NULL return), unlike the below which is undefined behavior or UB. A typical implementation of strdup(s) does not walk the length of s twice like the alternate might. A good strdup(s) will make one pass and use optimal copy code when the length warrants it. Perhaps by … Read more

Categories C Tags

How to iterate over a vector?

If you have access to C++11 you can use range-based for loops Otherwise you should use begin() and end() You can also use std::begin and std::end (these require C++11 as well) begin will return an iterator to the first element in your vector. end will return an iterator to one element past the end of your vector. So the order in which you get the elements iterating … Read more

How can I download Anaconda for python 3.6

As suggested here, with an installation of the last anaconda you can create an environment just like Cleb explained or downgrade python : With this second solution, you may encounter some incompatibility issues with other packages. I tested it myself and did not encounter any issue but I guess it depends on the packages you installed. If you … Read more

How do I select which GPU to run a job on?

The problem was caused by not setting the CUDA_VISIBLE_DEVICES variable within the shell correctly. To specify CUDA device 1 for example, you would set the CUDA_VISIBLE_DEVICES using or The former sets the variable for the life of the current shell, the latter only for the lifespan of that particular executable invocation. If you want to specify more than one device, use … Read more

Difference in make_shared and normal shared_ptr in C++

The difference is that std::make_shared performs one heap-allocation, whereas calling the std::shared_ptr constructor performs two. Where do the heap-allocations happen? std::shared_ptr manages two entities: the control block (stores meta data such as ref-counts, type-erased deleter, etc) the object being managed std::make_shared performs a single heap-allocation accounting for the space necessary for both the control block and the data. In the other … Read more