@@ -18,14 +18,15 @@ Classes and methods
1818
1919cimport cython
2020
21- from sage.categories.fields import Fields
2221from libc.limits cimport UINT_MAX
2322from libc.string cimport memset, memcpy
24-
25- from cysignals.memory cimport check_malloc, check_calloc, sig_free
23+ from memory_allocator cimport MemoryAllocator
2624
2725from sage.rings.integer cimport smallInteger
2826
27+ from sage.categories.fields import Fields
28+
29+
2930cdef class EvenlyDistributedSetsBacktracker:
3031 r """
3132 Set of evenly distributed subsets in finite fields.
@@ -168,17 +169,11 @@ cdef class EvenlyDistributedSetsBacktracker:
168169 cdef unsigned int * cosets # e array: cosets of differences of elts in B
169170 cdef unsigned int * t # e array: temporary variable for updates
170171
172+ # MANAGEMENT OF MEMORY
173+ cdef MemoryAllocator mem
174+
171175 def __dealloc__ (self ):
172- if self .diff != NULL :
173- sig_free(self .diff[0 ])
174- sig_free(self .diff)
175- if self .ratio != NULL :
176- sig_free(self .ratio[0 ])
177- sig_free(self .ratio)
178- sig_free(self .min_orb)
179- sig_free(self .B)
180- sig_free(self .cosets)
181- sig_free(self .t)
176+ pass
182177
183178 def __init__ (self , K , k , up_to_isomorphism = True , check = False ):
184179 r """
@@ -228,20 +223,21 @@ cdef class EvenlyDistributedSetsBacktracker:
228223 self .m = (q - 1 ) // e
229224 self .K = K
230225
231- self .diff = < unsigned int ** > check_calloc(q, sizeof(unsigned int * ))
232- self .diff[0 ] = < unsigned int * > check_malloc(q* q* sizeof(unsigned int ))
226+ self .mem = MemoryAllocator()
227+ self .diff = < unsigned int ** > self .mem.calloc(q, sizeof(unsigned int * ))
228+ self .diff[0 ] = < unsigned int * > self .mem.malloc(q* q* sizeof(unsigned int ))
233229 for i in range (1 , self .q):
234230 self .diff[i] = self .diff[i- 1 ] + q
235231
236- self .ratio = < unsigned int ** > check_calloc (q, sizeof(unsigned int * ))
237- self .ratio[0 ] = < unsigned int * > check_malloc (q* q* sizeof(unsigned int ))
232+ self .ratio = < unsigned int ** > self .mem.calloc (q, sizeof(unsigned int * ))
233+ self .ratio[0 ] = < unsigned int * > self .mem.malloc (q* q* sizeof(unsigned int ))
238234 for i in range (1 , self .q):
239235 self .ratio[i] = self .ratio[i- 1 ] + q
240236
241- self .B = < unsigned int * > check_malloc (k* sizeof(unsigned int ))
242- self .min_orb = < unsigned int * > check_malloc (q* sizeof(unsigned int ))
243- self .cosets = < unsigned int * > check_malloc (e* sizeof(unsigned int ))
244- self .t = < unsigned int * > check_malloc (e* sizeof(unsigned int ))
237+ self .B = < unsigned int * > self .mem.malloc (k* sizeof(unsigned int ))
238+ self .min_orb = < unsigned int * > self .mem.malloc (q* sizeof(unsigned int ))
239+ self .cosets = < unsigned int * > self .mem.malloc (e* sizeof(unsigned int ))
240+ self .t = < unsigned int * > self .mem.malloc (e* sizeof(unsigned int ))
245241
246242 x = K.multiplicative_generator()
247243 list_K = []
0 commit comments