deque

std::deque memory usage - Visual C++, and comparison to others

你离开我真会死。 提交于 2019-12-19 05:06:59
问题 Follow up to What the heque is going on with the memory overhead of std::deque? Visual C++ manages deque blocks according to the container element type using this: #define _DEQUESIZ (sizeof (value_type) <= 1 ? 16 \ : sizeof (value_type) <= 2 ? 8 \ : sizeof (value_type) <= 4 ? 4 \ : sizeof (value_type) <= 8 ? 2 \ : 1) /* elements per block (a power of 2) */ This results in very large memory footprint for small elements. By changing the 16 in the first line to 128 I was able to drastically

Why is it so slow iterating over a big std::list?

送分小仙女□ 提交于 2019-12-18 12:44:25
问题 As title suggests, I had problems with a program of mine where I used a std::list as a stack and also to iterate over all elements of the list. The program was taking way too long when the lists became very big. Does anyone have a good explanation for this? Is it some stack/cache behavior? (Solved the problem by changing the lists to std::vector and std::deque (an amazing data structure by the way) and everything suddenly went so much faster) EDIT: I'm not a fool and I don't access elements

Std::deque does not release memory until program exits

无人久伴 提交于 2019-12-17 20:23:25
问题 On linux, std::deque does not release memory until program exits. The complete code is below. Any help will be greatly appreciated! #include <deque> #include <vector> #include <string> #include <iostream> #include <boost/shared_ptr.hpp> #include <queue> #include <list> #include <cstdio> #include <cstdlib> typedef boost::shared_ptr<std::vector<int> > VecPtr; typedef std::deque< VecPtr > QueueType; char buf[1024]; char line[1024]; int main() { { int v=0; QueueType deq; for(int i=0; i<30;++i)

How Do I define a Double Brackets/Double Iterator Operator, Similar to Vector of Vectors'?

拟墨画扇 提交于 2019-12-17 18:09:11
问题 I'm porting code that uses a very large array of floats, which may trigger malloc failures from c to c++. I asked a question about whether I should use vectors or deques and Niki Yoshiuchi generously offered me this example of a safely wrapped type: template<typename T> class VectorDeque { private: enum TYPE { NONE, DEQUE, VECTOR }; std::deque<T> m_d; std::vector<T> m_v; TYPE m_type; ... public: void resize(size_t n) { switch(m_type) { case NONE: try { m_v.resize(n); m_type = VECTOR; } catch

What's the difference between deque and list STL containers?

你说的曾经没有我的故事 提交于 2019-12-17 17:26:37
问题 What is the difference between the two? I mean the methods are all the same. So, for a user, they work identically. Is that correct?? 回答1: From the (dated but still very useful) SGI STL summary of deque: A deque is very much like a vector: like vector, it is a sequence that supports random access to elements, constant time insertion and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle. The main way in which deque differs from

Is using std::deque or std::priority_queue thread-safe? [duplicate]

南笙酒味 提交于 2019-12-17 16:19:43
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: Is the C++ STL std::set thread-safe? Thread safety for STL queue I'm guessing it isn't, I just want to make sure. meaning 2 threads using the same std::deque using std::deque::push_back or push_front at the same time. Same question goes for std::priority_queue and the functions std::priority_queue::push and std::priority_queue::pop .. Are those containers thread-safe? Or I should personally program it to be

Why is ArrayDeque better than LinkedList

我与影子孤独终老i 提交于 2019-12-17 08:00:37
问题 I am trying to to understand why Java's ArrayDeque is better than Java's LinkedList as they both implement Deque interface. I hardly see someone using ArrayDeque in their code. If someone sheds more light into how ArrayDeque is implemented, it would be helpful. If I understand it, I will be more confident using it. I could not clearly understand the JDK implementation as to the way it manages head and tail references. 回答1: Linked structures are possibly the worst structure to iterate with a

Why is the array not showing up in the table view?

╄→гoц情女王★ 提交于 2019-12-13 07:05:03
问题 I am appending data from parse into an array, but when I try to load array in table view nothing shows up. The array is populated, but nothing is showing up. How do I fix this? class View2: UIViewController, UITableViewDataSource, UITableViewDelegate{ var ret = [String]() func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return ret.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell =

Function/Method pointers Pushed to a Deque

三世轮回 提交于 2019-12-13 01:05:41
问题 I am making a Queue for running functions. I put the functions that require being called into a std::deque<bool(*)()> Then I later on cycle through the deque calling each function and letting it run, sometimes even doing things based on the return. The problem I am having is actually with regards to placing these functions inside of the deque. I have this deque inside a class called A2_Game . I also have a class called Button . My code resembles the following: class Button { bool DoInput(); }

std::deque memory use

a 夏天 提交于 2019-12-12 09:18:52
问题 I have implemented a simple statistical engine to return rolling mean and variance using a deque to provide a data queue. The deque is constructed with a number of entries equal to the rolling number of values. When a new value arrives the oldest value is popped of the front and the new one pushed onto the back. I need to be sure that this is not going to grow in memory as it is expected to run as a background task for a long time. Does deque allocate on the heap in use? Are there flags that