Is it possible to request a code review?

rikki cattermole rikki at cattermole.co.nz
Fri Dec 15 08:37:27 UTC 2017


On 15/12/2017 8:15 AM, IM wrote:
> I'm still looking for feedback about these points:
> 
>    - Any candidate class that can be better switched to a struct or even 
> a template?

Template(d/s) symbols are only useful for making things more generic for 
the purpose of code reuse.

Next it comes to two things regarding class/struct usage.

1) Do you really need the inheritance capabilities with vtables?
2) Is it being passed by value versus reference?

If you don't need inheritance but do need to pass by reference a final 
class may be appropriate.

If you don't need to copy it around at all, use neither (remember what I 
said about singletons?).

The purpose of all of this is to make it cheaper at runtime, 
performance. If you want to write rubbish code while getting the job 
done (which is not a wrong way of doing things), then ignore all of this 
and model it as you please.

>    - The use of shared and __gshared, did I get those right? I find the 
> TLS concept unpleasant, because it makes me unsure what's the right 
> thing to do. For example:
>      - If a class that instances of which will be accessed by multiple 
> threads, should it be marked `shared`. For instance `TaskQueue` 
> (https://gitlab.com/3d_immortal/libdtasks/blob/master/src/tasks/TaskQueue.d#L9). 
> 
>      - What about the members of a class, do they ever need to be marked 
> as shared?
>      - Also, in this unittest : 
> https://gitlab.com/3d_immortal/libdtasks/blob/master/src/tasks/SingleThreadTaskRunner.d#L148, 
> I didn't mark `number` as shared, even though it is accessed by two 
> threads, and I didn't see any unexpected behavior (because the task 
> runners implicitly synchronize access to it using tasks and replies). 
> But in the other unittest here: 
> https://gitlab.com/3d_immortal/libdtasks/blob/master/src/tasks/ThreadPoolTaskRunner.d#L100, 
> I marked `number` as shared just because I believed I have to since it 
> will be accessed by many threads arbitrarily.

shared is little more than a way to tell the programmer what your 
intention is for a give bit of memory (with type safety but not codegen 
based safety).



More information about the Digitalmars-d mailing list