stdvector

Implement support for std::vector without std_vector.i

ぐ巨炮叔叔 提交于 2019-12-08 06:09:40
问题 Okay, I've already asked 2 questions about my problem and despite the fact that the replies were really helpful, I am not able to find an optimal solution for my problem. Let me explain my main objective/problem now. Due to some constraints I can't use std_vector.i in my swig interface, but I need to use a C++ object of (vector of vectors of string) vector<vector<string>> in Python. I implemented a solution where I am converting whole vector<vector<string> > to Python "List of Lists" wherein

conversion between std::vector and _variant_t

社会主义新天地 提交于 2019-12-08 05:02:48
问题 I need to convert between std::vector and _variant_t to avoid looping when writing/sending data into some file (database, Excel, etc.) Could you please let me know how to proceed with that? I was trying to get a std::vector<_variant_t> and somehow put into another _variant_t variable, but direct conversion is not supported and even if it's done there's no either method or some kind of wrapper to get this vector into a _variant_t variable. I would prefer not to deal with any loops. 回答1: A std:

OpenCV cv::Mat causing potential memory leak with std::vector

淺唱寂寞╮ 提交于 2019-12-08 05:00:26
问题 As it stands right now im trying to save an entire list of images in the form of cv::Mats inside of a vector for later processing. Right now I have something that looks like this: do { image = readimage(); cv::Mat mat = cv::Mat((length, width, CV_8UC4, image)); cv::Mat temp = mat.clone(); saved_images.push_back(); mat.release(); temp.release(); freeimagememory(image); } while(hasimage); This actually works. For exceptionally small lists of images it will store them just fine. However as I get

How would you manage a std::vector of structs with std::vectors with large range of sizes in both dimentions?

不羁的心 提交于 2019-12-08 03:56:28
I have a set of structures similar to: typedef struct { int a; int b; } ITEM; typedef struct { int orderID; std::vector<ITEM> items; } ORDER; typedef struct { int orderSetID; std::vector<ORDER> Orders; } ORDER_SET; The problem is that the number of orders ranges between 100,000 to 10,000,000 and the number of ITEMS in an ORDER ranges from 1 to 500. The issue is, as I build the ORDER_SET , I don't know how many ORDERs there will be. I do know when I add an ORDER how many ITEMS there will be. Here are some problems: 1) Ideally once I allocate the memory for all of the ORDERs using Orders.resize(

How would you manage a std::vector of structs with std::vectors with large range of sizes in both dimentions?

感情迁移 提交于 2019-12-08 03:13:26
问题 I have a set of structures similar to: typedef struct { int a; int b; } ITEM; typedef struct { int orderID; std::vector<ITEM> items; } ORDER; typedef struct { int orderSetID; std::vector<ORDER> Orders; } ORDER_SET; The problem is that the number of orders ranges between 100,000 to 10,000,000 and the number of ITEMS in an ORDER ranges from 1 to 500. The issue is, as I build the ORDER_SET , I don't know how many ORDERs there will be. I do know when I add an ORDER how many ITEMS there will be.

How to automatically maintain a list of class instances?

Deadly 提交于 2019-12-08 03:04:05
问题 In my C++ project, I have an Engine class and an Object class. My issue lies with how my instances of Object are created. Currently this is done through the use of a CreateObject(parameters) function in the Engine class. This adds a new instance of Object to an std::vector of Object instances. I want to maintain this list of instances of Object in my Engine class, but without the need for the CreateObject(parameters) function. My reason for this is so that I can create new classes that can

Before or after when adding to sets in C++

女生的网名这么多〃 提交于 2019-12-08 00:39:05
问题 Given my_type m; std::vector<my_type> v; Which runs more quickly? m.generate_data_inside_self(); v.push_back(m); Or v.push_back(m); v[0].generate_data_inside_self(); If the vector held pointers to the my_types then both would seem about the same. However when copying in the whole my_type object as in this example I think the 2nd would be faster as there is less to copy as the extra data only comes into existance after "m" is inside "v". edit: In the example in my program my_type looks sort of

initialize vector of pointers (automatically)

早过忘川 提交于 2019-12-07 20:31:38
问题 I encountered a compilation error when trying to initialize a vector of pointers to NULL by way of the std::vector constructor. I simplify the instruction to keep it simple: vector<int*> v (100,NULL) I guess it has something to do with an incompatibility between const T& value= T() (the parameter of the constructor) and the very value NULL, but I would appreciate some further explanation. Thank you 回答1: If you have the relevant C++11 support, you could use nullptr : std::vector<int*> v(100,

How does a C++ std::container (vector) store its internals (element address, access by index)?

青春壹個敷衍的年華 提交于 2019-12-07 19:39:26
问题 I am trying to "hack" a game (Red Alert 3), I try to make a program which shows the unit list of my opponents. As for that I first need to find a (static) pointer to my own list which I can do on single player. I have noticed this behaviour: (by looking at which addresses are changed by the add_unit code): if a units hasn't been build yet, create a new address for it (random?) and set the value to 1 (amount of units of that type) when the unit has been already build once in the game,

fast way to delete entries of STL vector of pointers

南笙酒味 提交于 2019-12-07 16:19:58
问题 I have a vector of pointers which I want to delete, but iterating over the vector and calling delete for each element is quite slow. Is there a faster way? Unfortunately I really need to store pointers, since I use a virtual superclass. Simplified, the class structure looks something like this: class VirtualSuperClass { protected: SomeType m_someMember; // ... public: virtual void doSomething() = 0; }; class Subclass_1 : public VirtualSuperClass { protected: SomeType m_someSubclassMember; //