[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GMP ref count
From: |
Hans Aberg |
Subject: |
GMP ref count |
Date: |
Wed, 25 Apr 2001 22:42:06 +0200 |
I experimented with a quick fix in order to put in all data in the _mp_d
field of __mpz_struct and __mpf_struct.
In file memory.c, I put in
size_t _mp_d_offset = 4 * sizeof(mp_limb_t);
#define malloc(size) ((char*)malloc(size + _mp_d_offset) + _mp_d_offset)
#define realloc(oldptr, new_size) ((char*)realloc((char*)oldptr -
_mp_d_offset, new_size + _mp_d_offset) + _mp_d_offset)
#define free(ptr) (free((char*)ptr - _mp_d_offset))
in order to reserve memory, and the __mpz_struct and __mpf_struct were
replaced by
typedef struct
{
mp_limb_t *_mp_d; /* Pointer to all. */
} __mpz_struct;
#define _mp_alloc _mp_d[-3]
#define _mp_count _mp_d[-2]
#define _mp_size _mp_d[-1]
typedef struct
{
mp_limb_t *_mp_d; /* Pointer to all. */
} __mpf_struct;
#define _mp_prec _mp_d[-4]
#define _mp_exp _mp_d[-3]
However, the code then breaks (as expected) in places such as
mpz_init (mpz_ptr x)
{
x->_mp_alloc = 1; /* Reference before allocation */
x->_mp_d = (mp_ptr) (*_mp_allocate_func) (BYTES_PER_MP_LIMB);
x->_mp_size = 0;
}
-- As I am not sufficiently familiar with the code, I decided to not now
try to identify the places where __mpz_struct and __mpf_struct fields are
accessed before the _mp_d field has been allocated.
However, if this could be done, one could make an experimental C++ wrap
using a ref count, to see how well it times relative the C version.
Hans Aberg
- GMP ref count,
Hans Aberg <=