Array append performance 2

Denis Koroskin 2korden at gmail.com
Sun Aug 31 02:42:23 PDT 2008


On Sun, 31 Aug 2008 04:58:10 +0400, dsimcha <dsimcha at yahoo.com> wrote:

> 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.

Static doesn't apply to a struct, only to inner classes, IIRC.



More information about the Digitalmars-d mailing list