Question

I'm just playing around with a grub-bootable C++ kernel in visual studio 2010.

I've gotten to the point where I have new and delete written and things such as dynamically allocated arrays work. I can use STL lists, for example. I can even sort them, after I wrote a memcpy routine. The problem is when I use the std::vector type. Simply constructing the vector sends the kernel off into la la land.

Obviously I'm missing a function implementation of some kind, but I looked through STL searching for it and came up empty-handed. It fails at the push_back:

vector<int> v;
v.push_back(1);

and disappears into the ether.

Any guesses as to what I'm missing?

Edit yes it's vector of int. Sorry for the confusion. Not only that, but it's not the constructor it fails on, it's a call to push_back.

Was it helpful?

Solution

As per our discussion above, creating a

std::vector<mySimpleStruct> v;

instead of a

std::vector<int> v;

appears to work correctly. This must mean the problem is with something being done in the specialization of some functions for std::vector in your standard template library. I'm assuming you're familiar with template specialization already, but in case you're not:

http://www.parashift.com/c++-faq-lite/templates.html#faq-35.7

Also, once you've figured out where the real problem is, could you come back and post the answer here? You have me curious about where the real problem is now, plus the answer may be helpful to others trying to build their own OS kernels.

OTHER TIPS

Stab in the dark: do you have new[] and delete[] implemented? A list will create one item at a time with new while a vector will likely allocate larger blocks of memory with new[].

Do you use a custom allocator or a default one?

You might try using a custom one just to see what allocations vector peforms that might destroy your implementation of the memory manager (this is probably what actually fails).

And yes, please post back once you solve it - it helps all other OSdevers out there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top