guile-user
[Top][All Lists]
Advanced

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

Re: vector typing


From: Andy Wingo
Subject: Re: vector typing
Date: Fri, 05 May 2006 09:59:03 +0200

Hi Dave,

On Thu, 2006-05-04 at 17:57 +0100, Dave Griffiths wrote:
> I admit I am confused about the typing of vectors - is there a quick way
> to create generalised vectors other than using scm_make_vector and adding
> each element individually with scm_vector_set_x?

According to the docs, uniform numeric vectors are generalized vectors,
and can be accessed via the americanly-spelled generalized-vector-ref
function. See:
http://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Generalized-Vectors.html#Generalized-Vectors

> Speed is an issue, as this is a graphics application
> (http://www.pawfal.org/fluxus) and I'm doing a lot of things with vectors.
> Are f32 better for speed reasons anyway?

1) uniform numeric vectors use less memory (32 bits versus a pointer to
a double-cell (2*sizeof(void*)) on the heap)

2) therefore, from C you don't need to be dereferencing pointers and
checking types in inner loops

3) also, you can get the contiguous array of f32 values, which you can't
do with a normal vector

So yes, for speed a uniform vector is a big win. If you can refactor
algorithms to deal in uniform vectors, with the actual operations
implemented in C, you can approach the speed of a C-only solution I
think.

Cheers,
-- 
Andy Wingo
http://wingolog.org/





reply via email to

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