mldonkey-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of


From: pango
Subject: [Mldonkey-users] [patch #4510] IP: Save Memory by using chars instead of int
Date: Wed, 12 Oct 2005 21:52:31 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050831 Galeon/1.3.20 (Debian package 1.3.20-1)

Follow-up Comment #3, patch #4510 (project mldonkey):

Chars may be 8 bit values, it doesn't mean that they use just that amount of
storage : memory is allocated in "words" (4 bytes on 32 bits architectures, 8
bytes on 64 bits architectures). The question is then, does the ocaml compiler
"pack" char tuples.

Int32s are indeed boxed, which means that they also use more than 32 bits of
memory. In fact, all but enumerated types are boxed, and enumerated types are
stored on 31 bits, so a 32 bits value cannot use 4 bytes of memory).
A solution, as suggested on #ocaml on Freenode, may be to use int * int,
storing 16 bits in each.

I wrote the program below to evaluate the different solutions. It creates
1000000 values of the tested type, using an array, then kill itselfs with
SIGABRT. You can then check the size of the core dump (be sure ulimit doesn't
prevent core dumps from being generated):

(* compile with ocamlopt -o test unix.cmxa test.ml *)
let number = 1000000
let new_ip (a:int) (b:int) (c:int) (d:int) =
(* 0 (* reference *) *)
(* a, b, c, d (* 4 ints *) *)
(* char_of_int a, char_of_int b, char_of_int c, char_of_int d (* 4 chars *)
*)
  ((a lsl 8) lor b, (c lsl 8) lor d) (* 2 ints *)
let a = Array.init number (fun _ -> new_ip 1 2 3 4)
let _ =
  Unix.kill (Unix.getpid ()) 6

Results:
-rw-------  1 root root 17465344 2005-10-12 21:29 core.2ints
-rw-------  1 root root 26370048 2005-10-12 21:28 core.4chars
-rw-------  1 root root 26374144 2005-10-12 21:28 core.4ints
-rw-------  1 root root  4751360 2005-10-12 21:27 core.reference

I wrote a patch to save IPv4 numbers as int * int, but it's still untested.

By the way, on 64 bits architectures, a simple int is enough to store an
IPv4. And by the time we all switched to 64 bits boxen, we'll probably have
to store IPv6 numbers ;)
    _______________________________________________________

Additional Item Attachment:

File name: store_ips_as_2_ints.patch      Size:5 KB

<http://savannah.nongnu.org/patch/download.php?item_id=4510&item_file_id=5318>

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/patch/?func=detailitem&item_id=4510>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.nongnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]