Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Language Hype

Name: Anonymous 2010-12-15 17:51

It's an unknown fact that most GNU utils written in C never free up the memory they allocate, which usually results in memory leaks.

You may wonder, why? It's because C lacks RAII.

Same goes for D; although D does have RAII, its Garbage Collector creates memory leaks by allocating and never freeing ridicolously large memory chunks.

This code allocates 41,688 bytes, and never frees it:

import tango.io.Stdout;

void main(char[][] args)
{
    Stdout("Hello World!").newline();
}


Imagine the memory chunk allocated by the GC for a ``bigger'' application.

Yet D & C folks claim to be better than C++...

Name: Anonymous 2010-12-15 20:20

RAII
(define malloc
  ; get malloc through ffi
  (lambda (size)
    (display "malloc'ed ")
    (display size)
    (display " bytes")
    (newline)
    (lambda ()
      size)))

(define free
  ; get free through ffi
  (lambda (ptr)
    (display "freed ")
    (display (ptr))
    (display " bytes")
    (newline)))
   

(define-syntax with-malloc
  (syntax-rules ()
    ((with-malloc ((ptr args ...) ...) b ...)
     (let ((ptr (malloc args ...)) ...)
       b ...
       (begin
         (free ptr) ...)))))


> (with-malloc ((p 256)
              (t 64)
              (r 65536))
   ; play with the pointers
   (+ (p) (t) (r)))
malloc'ed 256 bytes
malloc'ed 64 bytes
malloc'ed 65536 bytes
freed 256 bytes
freed 64 bytes
freed 65536 bytes
>


LOL WATCH ME I'M SO SEPPLES

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List