Re: C++ sucks for games
From: Adam Warner (usenet_at_consulting.net.nz)
Date: 11/17/04
- Next message: Stefan Scholl: "Re: Lisp and Extreme Programming?"
- Previous message: Gerry Quinn: "Re: C++ sucks for games"
- In reply to: rif: "Re: C++ sucks for games"
- Next in thread: Duane Rettig: "Re: C++ sucks for games"
- Reply: Duane Rettig: "Re: C++ sucks for games"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 18 Nov 2004 01:57:30 +1300
Hi rif,
>> Would it help making arrays of (unsigned-byte 8) or (unsigned-byte 32)
>> and writing inlined accessor functions then?
>>
>> Kind regards,
>>
>> Hannah.
>
> It will help for some but not all applications. If you want to have a
> struct whose fields are all the same type, and that type can be inlined
> in arrays, then you can just allocate a big array of that type and build
> syntax to do the right thing. If your structs contain fields of
> different types (say, (unsigned-byte 32)'s *and* double-float's), then
> you have to either pay a memory penalty or move to a "multiple arrays"
> setup (what would naturally be an array of structs, where each struct is
> a two int's and a double-float, becomes an array of ints and an array of
> double-floats).
Not necessarily. Here's single array access for (unsigned-byte 32)'s and
double-float's for CMUCL and SBCL:
(let ((a (make-array 99 :element-type '(unsigned-byte 32)
:initial-element 0)))
(defun get-int (i)
(aref a (* i 3)))
(defun set-int (i j)
(setf (aref a (* i 3)) j))
(defun get-df (i)
(#+cmu kernel:make-double-float #+sbcl sb-kernel:make-double-float
(aref a (+ (* i 3) 1)) (aref a (+ (* i 3) 2))))
(defun set-df (i j)
(setf (aref a (+ (* i 3) 1)) (#+cmu kernel:double-float-high-bits
#+sbcl sb-kernel:double-float-high-bits j))
(setf (aref a (+ (* i 3) 2)) (#+cmu kernel:double-float-low-bits
#+sbcl sb-kernel:double-float-low-bits j))
j))
* (set-df 10 3.14d0)
3.14d0
* (get-df 10)
3.14d0
* (set-int 10 34)
34
* (get-int 10)
34
Your structure could only have one slot for an array. You could build
function or macro syntax to access the individual elements.
Not as efficient as you'd like but it's still only an extra array
lookup for each integer.
Regards,
Adam
- Next message: Stefan Scholl: "Re: Lisp and Extreme Programming?"
- Previous message: Gerry Quinn: "Re: C++ sucks for games"
- In reply to: rif: "Re: C++ sucks for games"
- Next in thread: Duane Rettig: "Re: C++ sucks for games"
- Reply: Duane Rettig: "Re: C++ sucks for games"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|