Re: GC vs. Manual Memory Management Real World Comparison

2012-09-12 Thread Felix Hufnagel

class Foo
{
@safe nothrow:
void method_is_nothrow(){}
void method_is_also_nothrow(){}
}


or

class Foo
{
@safe nothrow
{   
void method_is_nothrow(){}
void method_is_also_nothrow(){}
}
}

no need to append it to every single method by hand...



Am 12.09.2012, 04:38 Uhr, schrieb SomeDude :


On Tuesday, 11 September 2012 at 10:28:29 UTC, bearophile wrote:

SomeDude:

It's a bad solution imho. Monitoring the druntime and hunting every  
part that allocates until our codebase is correct like Benjamen Thaut  
is a much better solution


Why do you think such hunt is better than letting the compiler tell you  
what parts of your program have the side effects you want to avoid?


Bye,
bearophile


My problem is you litter your codebase with nogc everywhere. In  similar  
fashion, the nothrow keyword, for instance, has to be appended just  
about everywhere and I find it very ugly on its own. Basically, with  
this scheme, you have to annotate every single method you write for each  
and every guarantee (nothrow, nogc, nosideeffect, noshared, whatever you  
fancy) you want to ensure. This doesn't scale well at all.


I would find it okay to use a @noalloc annotation as a shortcut for a  
compiler switch or a an external tool to detect allocations in some part  
of code (as a digression, I tend to think D @annotations as compiler or  
tooling switches. One could imagine a general scheme where one  
associates a @annotation with a compiler/tool switch whose effect is  
limited to the annotated scope).
I suppose the tool has to build the full call tree starting with the  
@nogc method until it reaches the leaves or finds calls to new or  
malloc; you would have to do that for every single @nogc annotation,  
which could be very slow, unless you trust the developer that indeed his  
code doesn't allocate, which means he effectively needs to litter his  
codebase with nogc keywords.



--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/


Re: JPG and PNG decoder

2012-06-21 Thread Felix Hufnagel
it's not that hard to write a baseline jpeg encoder. it's not harder than  
decoding.

there are many tutorials and examples online.




Am 17.06.2012, 09:55 Uhr, schrieb cal :


On Sunday, 17 June 2012 at 07:07:35 UTC, Philippe Sigaud wrote:

Still, I'm interested in writing a JPEG/PNG to disk from a
ubyte[3][][], or whatever.


Do you mean that you want to encode a ubyte array to disk as JPEG/PNG?  
Encoding a JPEG would be a bit of work I think, the format's kind of a  
monster. PNG should be easier, depending on how good you want the  
compression to be. If you don't care too much about compression level,  
you simply zlib compress the data, write it out by image row/scanline,  
include appropriate header and chunk info, and you're done. I'll give a  
simple encoder a go if you think you could use it.


Cheers,
cal




--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/