GC, the simple solution

Walter Bright newshound at digitalmars.com
Fri Jun 9 09:42:59 PDT 2006


Sean Kelly wrote:
> Walter Bright wrote:
>> You can use D arrays. Just allocate them using malloc (or statically 
>> allocate them). Don't concatenate them.
> So then I'd just manually set the ptr and len members?  Sounds 
> reasonable, provided everyone behaves and uses the copy on write idiom 
> you suggest.

int *p = cast(int *)calloc(dim, sizeof(int));
int[] a = p[0 .. dim];

>> C is very good for writing real time code, and you can write "C"-style 
>> code in D, and it will behave exactly like the corresponding C code. 
>> You can call printf, strcpy, malloc, etc., which will behave just like 
>> C's printf, strcpy, and malloc because they *are* C's functions. It 
>> will not do a gc collect unless the code allocates gc memory, and it 
>> will ONLY do a gc collect during such an allocation.
> At times I've considered extending thread support to allow for the 
> creation of detached threads, but it simply seems to error-prone to be 
> worthwhile.  I think you're right in that if someone is doing real-time 
> programming then they shouldn't expect much hand-holding, because the 
> assumptions involved offer too great a risk of unexpected behavior.

I agree that realtime programming is a special type of programming, and 
that someone doing it should be a more advanced programmer. You can't 
just take any random code (in any language), make it realtime, and 
expect it to work properly. It's got to be engineered for the 
peculiarities of realtime requirements.


>> Heck, my old Empire game was written in C. I renamed the files from .c 
>> to .d, did a few minor syntactic edits, and voila! it was now in D. It 
>> runs exactly the same.
> 
> Yup.  Though it's worth noting that D has been heavily influenced by 
> your particular programming style.  Not at all a bad thing, but it does 
> imply that you are less likely than anyone else to experience code 
> translation problems :-)  On a related note, I sometimes wonder if Sid 
> Meier credits you anywhere for effectively creating the genre that's 
> made him so successful ;-)

Nope :-)



More information about the Digitalmars-d mailing list