mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
.. from C to a C++ class. Moved the original code to a sundirectory for reference and moved all the global variables and methods into a new class called Voronoi. .. the code still needs more work but wanted to remove the global variables as there were lots and a big risk they interact with other parts of the codebase and libraries.
58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
|
|
/*** MEMORY.C ***/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h> /* malloc(), exit() */
|
|
|
|
#include "vdefs.h"
|
|
|
|
extern int sqrt_nsites, siteidx ;
|
|
|
|
void
|
|
freeinit(Freelist * fl, int size)
|
|
{
|
|
fl->head = (Freenode *)NULL ;
|
|
fl->nodesize = size ;
|
|
}
|
|
|
|
char *
|
|
getfree(Freelist * fl)
|
|
{
|
|
int i ;
|
|
Freenode * t ;
|
|
if (fl->head == (Freenode *)NULL)
|
|
{
|
|
t = (Freenode *) myalloc(sqrt_nsites * fl->nodesize) ;
|
|
for(i = 0 ; i < sqrt_nsites ; i++)
|
|
{
|
|
makefree((Freenode *)((char *)t+i*fl->nodesize), fl) ;
|
|
}
|
|
}
|
|
t = fl->head ;
|
|
fl->head = (fl->head)->nextfree ;
|
|
return ((char *)t) ;
|
|
}
|
|
|
|
void
|
|
makefree(Freenode * curr, Freelist * fl)
|
|
{
|
|
curr->nextfree = fl->head ;
|
|
fl->head = curr ;
|
|
}
|
|
|
|
int total_alloc ;
|
|
|
|
char *
|
|
myalloc(unsigned n)
|
|
{
|
|
char * t ;
|
|
if ((t=malloc(n)) == (char *) 0)
|
|
{
|
|
fprintf(stderr,"Insufficient memory processing site %d (%d bytes in use)\n",
|
|
siteidx, total_alloc) ;
|
|
return(0) ; // was exit(0) in original source, we aint having that here !!!
|
|
}
|
|
total_alloc += n ;
|
|
return (t) ;
|
|
}
|