Category : memory-management

how are you doing? I was running the valgrind memory leak test in a thread management program and I got this error window while testing. The message is as fallows: "Sorry, the program "memcheck-amd64-linux" closed unexpectedly. Your computer doesn’t have enought memory to automatcally analise the problem and send a report to the developers". After ..

Read more

I have a member variable called neuronLayers which is of type std::vector<Eigen::RowVectorXf*> neuronLayers and another called weights of type std::vector<Eigen::MatrixXf*>. As part of a forward propagation function, I need to multiply values from these two vectors and keep a pointer to that value. I’ve already made sure the sizes of the dimensions of values I’m ..

Read more

I’m extremely new to DLL writing/usage, and have written a function within the DLL that accepts a string, and returns another string to the executable as output. #define DECL_EXPORT extern "C" __declspec(dllexport) DECL_EXPORT char * organizeArgs(const char * args) { uint32 outputLen; … char * result = new char[outputLen]; … return result; } The easiest ..

Read more

Here’s part of a function: std::queue<std::string>* shunting_yard(std::vector<std::string> input){ std::queue<std::string>* output = new std::queue<std::string>(); … return output; I’ve dynamically allocated queue output is pointing to on the heap. However, when I try to free/delete the queue in int main() I get an error because output is declared out of scope. Considering the fact that I’m returning ..

Read more

I’m trying to replace a raw pointer implementation to smart pointer, so in this function call int id = std::stoi(idToken->second); auto newNode = std::find_if(_nodes.begin(), _nodes.end(), [&id](GraphNode *node) { return node->GetID() == id; }); I’m trying to change the raw pointer (GraphNode) to GraphNode unique ptr, to set the exclusive ownership of graphnode to the class ..

Read more

I have two related questions regarding creating a numpy array using the C api. Given a newly created numpy array: std::vector<double> vec({0.1, 0.2}); int length = vec.size(); double* data = new double[length]; std::copy(vec.begin(), vec.end(), data); PyObject* obj = PyArray_SimpleNewFromData(1, &length, NPY_DOUBLE, (void*)data); How do I ensure proper memory management? I didn’t want to give PyArray_SimpleNewFromData ..

Read more