Array append performance 2
dsimcha
dsimcha at yahoo.com
Sat Aug 30 17:58:10 PDT 2008
Nice work on the reference template. I had thought that the typeid(T).flags()
would be inlined, then constant folded, but CTFE doesn't work on it, so I guess
not. Probably pretty negligible, but if I have a template laying around to do
this at compile time, I may as well use it.
Also, to answer your question, you do need to call hasNoPointers() each time you
realloc.
import std.stdio, std.gc, std.process;
void main() {
uint[] foo = (cast(uint[]) malloc(uint.sizeof))[0..1];
hasNoPointers(foo.ptr);
foo = cast(uint[]) realloc(foo.ptr, 100_000 * uint.sizeof)[0..100_000];
//Commenting next line out causes severe mem leaks.
hasNoPointers(foo.ptr);
foreach(ref f; foo) {
f = cast(uint) test(); //Create false pointers.
}
system("pause"); //So mem usage can be checked.
}
uint* test() {
return (new uint[1_000]).ptr;
}
Oh, one more thing: What's a static struct as opposed to a regular struct? I've
never seen it used before. I had assumed that this means a struct composed only
of static members, but apparently not.
More information about the Digitalmars-d
mailing list