Archive for February 14th, 2008

Why?

Thursday, February 14th, 2008

When I change a comment in a header file, why does the compiler rebuild everything ?

It’s smart enough to know it’s a comment, right? (Comments have a different color after all). So I would like to have a cool option not to mark a file as “modified” when I just change a comment. Granted, it probably would fail in some cases where macros are over-used or something, but it would work pretty well otherwise, wouldn’t it?

TODO: stack-allocated container?

Thursday, February 14th, 2008

I was browsing a codebase when I noticed this usage pattern, several times:

void SomeFunction()
{

vector<some class> localVector;

localVector.push_back(some data);

}

In considered cases, the push_back doesn’t always happen and the number of pushed elements is not known ahead of time (i.e. there’s a good reason why a dynamic array is used). However what happens is that only a few elements are usually written to the array, and overall a small amount of memory is actually needed. So, it’s a bit painful to do an allocation/deallocation for this.

So it might be useful to allocate the initial memory on the stack (i.e. with alloca) and only switch to “real” memory allocations the first time the array is resized. If we stack-allocate say 16K initially, it could significantly reduce the number of small allocations performed by that kind of code. Something to try at some point.

EDIT: done! Works nicely.

shopfr.org cialis