struct vs class for a simple token in my d lexer

Roman D. Boiko rb at d-coding.com
Mon May 14 09:22:44 PDT 2012


On Monday, 14 May 2012 at 15:44:54 UTC, Tobias Pankrath wrote:
> On Monday, 14 May 2012 at 15:10:25 UTC, Roman D. Boiko wrote:
>> (Subj.) I'm in doubt which to choose for my case, but this is 
>> a generic question.
>>
>> http://forum.dlang.org/post/odcrgqxoldrktdtarskf@forum.dlang.org
>>
>> Cross-posting here. I would appreciate any feedback. (Whether 
>> to reply in this or that thread is up to you.) Thanks
>
>
> struct Token
> {
>     TokenType type;
>     string content; // type may as well be template parameter
>     Area loc;   // basically: ((x1, y1), (x2, y2))
> }
>
> That's how my Token look like. The 2 or 3 times every token 
> get's copied isn't worth a heap allocation with small type like 
> this.
Yes, except that the array of tokens for big files requires a lot 
of **continuous** space (13.5M for std.datetime, up to 2M for a 
few others in phobos & druntime). The array of references would 4 
times less. Out of memory usually happens when the system cannot 
find a big enough chunck of memory, not when there is no 
available memory.

On the contrary, I think that 10-20M on rare cases is not too 
much.

Why I use the array I'll describe in the next post.


More information about the Digitalmars-d-learn mailing list