[Solved] std::vector push_back results in access Violation

Dict* test = (Dict*)malloc(sizeof(Dict)); does not do what you think it does. malloc allocates a block of memory, but does not initialize it. So later on, when you call test->nodes.push_back, you’re calling into uninitialized memory. Undefined behavior. In your case, it crashes. The solution here is allocate test with new, which will initialize both test … Read more

[Solved] speeding vector push_back [closed]

Indeed push_back may trigger reallocation, which is a slow process. It will not do so on every single push_back though, instead it will reserve exponentially more memory each time, so explicit reserve only makes sense if you have a good approximation of resulting vector size beforehand. In other words, std::vector already takes care of what … Read more