473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

my little implementation of malloc

is it possible that a
malloc function that use a nobody student
is better than all yours :)

How many errors do you see?

Bug1: memory<13MB
Bug2:
it seems do you have to write you own sprintf "Ps_m"
Ps_m(char* out, int len, char* fmt, ...)
that has the len of array in the second arg

#include <windows.h>
#include <winbase.h>
#include <wincon.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <winuser.h>

#include "winb.h"
#define IVA_ INVALID_HANDLE_ VALUE

#define P printf
#define W while
#define F for
#define R return

/* MEM_LIMIT e' il limite del numero di diversi puntatori
ritornati da malloc_m */
#define MEM_LIMIT 200000
#define MAX_ARRAYS 255

/*************** **********CCCCC CC************* *************** ******/
#ifdef __cplusplus
extern "C" {
#endif

void* malloc_sys(int n)
{if(n<0) R 0;
R (void*)LocalAll oc(LMEM_FIXED, n);
}

void free_sys(void* p){ LocalFree(p); }

void* realloc_sys(voi d *p, int nbytes)
{int k;
uns a, r, j, i;
char *p1, *p2;

if(nbytes<0) R 0;
k=LocalSize(p);
if(k<0) R 0;
p1= (char*) LocalAlloc(LMEM _FIXED, nbytes);
if(p1==0) R 0;
i = k<=nbytes? k: nbytes;
a=i/(sizeof(int)); r=i&(sizeof(int )-1);
F(j=0, p2=(char*)p; j<a; ++j)
((int*)p1)[j]=((int*)p2)[j];
F(i=4*j, r+=i; i<r; ++i)
p1[i]=p2[i];
LocalFree(p);
R p1;
}

#define NALLOC 1024
// 1024 /* numero minimo di unita' richieste */
// 1024*256*8=1024 *1024*2 = 2 mega

static unsigned yuyuy=0;
typedef double Align; /* per allineare alla double */

union header { /* header del blocco */
struct {union header* ptr; /* blocco successivo in free list */
unsigned size; /* dimensione di questo blocco */
}s;
Align x; /* forza l'allineamento dei blocchi */
}; /* sizeof header == 4+4 = 8 */

typedef union header Header;
static Header base; /* lista vuota per iniziare */
static Header *freep=NULL; /* inizio della free list */

static char name_ [ 1100 ] = {0}; /* name_== nome routines
chiamate */
static char memo_ [ 300 ] = {0}; /* stringa ove errori
trovati in memoria */
static int n_i_ = 0 ;
int libero_m_ = 0 ; /* libero_m_==1 controllo tutti i
vettori a
ogni chiamate di free(); serve insieme a name_ per individuare le
routines che
sovrascrivono la memoria che non hanno (e.g. if(libero_m_)
init_w("nome_ro utines");) */

typedef struct {
void *p;
unsigned size;
unsigned piu;
unsigned meno;
}vettore_array;

static vettore_array **p_p_p_=0; /* lista di struct di puntatori
ritornati da malloc_m */
static int i_i_i_=0; /* attuale indice nella lista */
static int m_m_m_=0; /* massimo indice nella lista */
static char **list_ =0; /* lista dei vettori richiesti al
sys */
static int list_i_=0;
static int list_m_=0;
static int show_si =0;

static int mem_init(int siz)
{vettore_array **pp;
int j;
/*---------------------*/
//P("p_p_p_=%p i_i_i_==%u siz=%u ", (void*) p_p_p_, i_i_i_, siz );
if(siz<0) R 0;
if(p_p_p_==0)
{pp= (vettore_array* *) malloc_sys( (siz+1) * sizeof *pp );
if(pp==0) R 0;
F( j=0; j<siz; ++j)
{pp[j]= (vettore_array* ) malloc_sys(size of(vettore_arra y));
if(pp[j]==0)
{if(j!=0)
F( --j ; j!=0 ; --j)
free_sys( (void*) pp[j] );
free_sys((void* ) pp[0]); free_sys((void* ) pp); R 0;
}
}
show_si=0;
}
else { if(siz==m_m_m_) R 1;
else if(siz < m_m_m_) /* dovrebbe distruggere la
memoria eccessiva */
{ if(siz<=i_i_i_) R 1; /* la 1024ma volta che viene
chiamato free_m()*/
F(j=siz; j<m_m_m_; ++j) // v[0]...v[size]=size+1
free_sys((void* ) p_p_p_[j]);
pp=(vettore_arr ay**) realloc_sys(p_p _p_, (siz + 1) *
sizeof *pp );
if(pp==0) {P("Fallimento realloc\n"); m_m_m_ = siz; R
1;}
/* ritorna senza cambiare niente */
goto label;
}
pp= (vettore_array* *) realloc_sys( (void*) p_p_p_, (siz + 1)
* sizeof *pp);
if(pp==0) {P("Fallimento realloc\n"); R 0;}
if( siz i_i_i_)
{ F( j=i_i_i_; j<siz; ++j)
{
pp[j]= (vettore_array* ) malloc_sys(size of(vettore_arra y));
if(pp[j]==0)
{if(j!=0)
F( --j ; j!=0 ; --j)
free_sys( (void*) pp[j] );
free_sys((void* ) pp[0]); R 0;
}

}
}
}
label: ;
m_m_m_ = siz; p_p_p_=pp; R 1;
}
/* malloc_m: allocatore di memoria */
void* malloc_m(unsign ed nbytes)
{Header *p, *prevp;
unsigned nunits, *k, *kk, led, size;
double dnm;
Header* morecore(unsign ed);
unsigned verifica_all_m( void );
void stato_mem(void) ;
/*-------------------------------*/
if(libero_m_)
{if(verifica_al l_m()==0) stato_mem();}

if(i_i_i_>MEM_L IMIT || nbytes==0 ) R 0;
if(i_i_i_>=m_m_ m_)
{if(mem_init( i_i_i_ + MAX_ARRAYS ) == 0) R 0;}
nunits = nbytes + sizeof(Header);
nunits = nunits/sizeof(Header) +
(( nunits%sizeof(H eader) >sizeof(unsigne d) ) ? 1: 0) + 1;
if((prevp=freep )==NULL) /* non esiste la free list */
{ base.s.ptr=free p=prevp=&base; base.s.size=0; }
for(p=prevp->s.ptr; ; prevp=p, p=p->s.ptr)
{if(p->s.size>=nunits ) /* spazio insufficiente */
{if(p->s.size==nunits ) /* esattamente */
{prevp->s.ptr = p->s.ptr;}
else /* alloca la parte finale */
{p->s.size -= nunits;
p += p->s.size;
p->s.size =nunits;
}
freep = prevp;
/*************** *** Blocco aggiunto ************/
size = nbytes;
led = (size % sizeof(unsigned )!=0) ? 1: 0;
k = (unsigned*)(p+1 ); kk=k; --k;
kk[size/sizeof(unsigned )+ led]=(uns)(p+1);
p_p_p_[i_i_i_]->meno = *k;
p_p_p_[i_i_i_]->piu = kk[size/sizeof(unsigned )+ led];
p_p_p_[i_i_i_]->size = size;
p_p_p_[i_i_i_++]->p = (void*)(p+1);
/*************** *************** *************** **/
return (void*) (p+1);
}
if(p==freep) /* la free list e' terminata */
{ // ho aggiunto le seguenti 11 righe
dnm = yuyuy + (nunits<NALLOC ? NALLOC: nunits);
dnm = (dnm *8.0)/1024000.0; // tutta la memoria in MB
if(dnm 13.1 ) G lab90; // se memoria 13.1MB esci
if((p=morecore( nunits)) == NULL)
{
lab90:;
if(stdout_m!=0 && stdout_m->fd!=(int)IVA _)
P("\nErrore: memoria insufficiente\n ");
exit_m(1); // voglio uscire
return NULL; /* non c'e' piu' spazio */
}
yuyuy += (nunits<NALLOC ? NALLOC: nunits);
/* numero di unita' di mem. richieste al sistema */
}
}
}
/*
unsigned verifica_all_m( void )
Ritorna il numero degli elementi;
se il numero degli elementi e' 0 ritorna (unsigned) -1
se errori di out of bound per qualche puntatore ritorna 0
*/
unsigned verifica_all_m( void )
{unsigned *k, *kk, xk, xkk, led;
int j;
/*----------------*/
if( p_p_p_==0 || i_i_i_==0 ) R -1;
F(j=0 ; j < i_i_i_ ; ++j)
{k = (unsigned*) (p_p_p_[j]->p); kk=k; --k;
led = (p_p_p_[j]->size % sizeof(unsigned )!=0) ? 1: 0;
if( (xk=kk[p_p_p_[j]->size/sizeof(unsigned ) + led]) !=
(xkk=p_p_p_[j]->piu) )
{ Ps_m(memo_ , 300, "verifica_all_m MEM_+ p=%p size=%u
p[-1]=%u p[max]=%u n:v=%u:%u",
p_p_p_[j]->p, p_p_p_[j]->size, p_p_p_[j]->meno,
xkk, xk, xkk);
if(n_i_>2) name_[ n_i_ - 2 ]='+';
return 0;
}
if( (xk=*k) != (xkk=p_p_p_[j]->meno) )
{ Ps_m(memo_ , 300, "verifica_all_m MEM_- p=%p size=%u
p[-1]=%u p[max]=%u n:v=%u:%u",
p_p_p_[j]->p, p_p_p_[j]->size, xkk,
p_p_p_[j]->piu, xk, xkk);
if(n_i_>2) name_[n_i_ - 2]='-';
return 0;
}
}
R i_i_i_;
}

void verifica_all( void )
{if(verifica_al l_m( )==0)
{P("Errore nella memoria\n");
if(*memo_ !=0 && *name_ != 0 )
P("memo=%s name=%s\n", memo_, name_ );
}
}

/* unsigned verifica_m( void* pointer, int *jj)
-se pointer==0 ritorna
1 se tutto e' cancellato
2 se tutto e' cancellato tranne il puntatore iniziale
3 altrimenti
-se pointer!=0 ritorna
0 se il vettore puntato da pointer fa parte della lista
1 se tutto e' cancellato
7 se il vettore puntato da pointer non fa parte della lista
8 se il vettore puntato da pointer fa parte della lista
ma ci sono errori di scrittura "out of bounds" 'iniziali'
9 se il vettore puntato da pointer fa parte della lista
ma ci sono errori di scrittura "out of bounds" 'finali'
*/
unsigned verifica_m( void* pointer, int *jj)
{unsigned *k, *kk, xk, xkk, led;
int j;
/*----------------*/
if(jj!=0) *jj=0;
if(pointer==0)
{if( i_i_i_==0 && p_p_p_==0 ) R 1;
else if(i_i_i_==0) R 2;
else R 3;
}
if(p_p_p_==0 ) R 1;

F(j=i_i_i_-1 ; j>=0 ; --j)
if( p_p_p_[j]->p == pointer ) break;

if(j<0) {P("\nverifica_ mMEM_0 0x%p indice=%u ", pointer, i_i_i_ );
if(*memo_ && *name_ )
P( "memo=%s name=%s", memo_, name_ );
P("\n");
if(n_i_>2) name_[n_i_ -2]='0';
R 7;
}
k = (unsigned*) pointer; kk=k; --k;
led = (p_p_p_[j]->size % sizeof(unsigned )!=0) ? 1: 0;
*jj=j;
if( (xk=kk[p_p_p_[j]->size/sizeof(unsigned ) + led]) !=
(xkk=p_p_p_[j]->piu) )
{ P("\np=0x%p size=%u p[-1]=%u p[max]=%u ", pointer,
p_p_p_[j]->size, *k, xk);
P("verifica_mME M_+ n:v>%u:%u\n", xk, xkk);
if(n_i_>2) name_[ n_i_ - 2 ]='+';
return 8;
}
if( (xk=*k) != (xkk=p_p_p_[j]->meno) )
{ P("\np=0x%p size=%u p[-1]=%u p[max]=%u ", pointer,
p_p_p_[j]->size, xkk, p_p_p_[j]->piu);
P("verifica_mME M_- n:v>%u:%u\n", xk, xkk);
if(n_i_>2) name_[n_i_ - 2]='-';
return 9;
}
else R 0;
}

unsigned verifica_p_m( void* pointer)
{int jj; R verifica_m( pointer, &jj);}

static void free_list_m(voi d)
{W(list_i_!=0)
{--list_i_; free_sys(list_[list_i_]);}
free_sys(list_) ; list_=0; list_m_=0; freep=NULL;
}

static void free_vettore_m( void)
{int j;
if(p_p_p_==0) { m_m_m_=0; i_i_i_=0; R;}
F(j=0; j<m_m_m_; ++j) // v[0]...v[size]=size+1
free_sys((void* ) p_p_p_[j]);
free_sys((void* ) p_p_p_);
p_p_p_=0; m_m_m_=0; i_i_i_=0;
}
static void inserisci(void* ap, unsigned jk, int j)
{Header *bp, *p, *r;
static unsigned f_cont=0;
/*-------------------*/
if(jk==0) ++f_cont;
bp = (Header*)ap - 1; /* punta all'header del blocco */
F( r=p=freep; !(bp>p && bp < p->s.ptr); r=p, p=p->s.ptr )
if( p >= p->s.ptr && (bp>p || bp < p->s.ptr) )
break; /* il blocco liberato e'
ad un estremo della lista*/
if(jk) goto label;
/*************** *************** **************/
if(j != i_i_i_ - 1)
{p_p_p_[j]->p = p_p_p_[i_i_i_ - 1]->p;
p_p_p_[j]->size = p_p_p_[i_i_i_ - 1]->size;
p_p_p_[j]->meno = p_p_p_[i_i_i_ - 1]->meno;
p_p_p_[j]->piu = p_p_p_[i_i_i_ - 1]->piu;
}
p_p_p_[--i_i_i_]->p =0; p_p_p_[i_i_i_]->size=0;
p_p_p_[i_i_i_]->meno=0; p_p_p_[i_i_i_]->piu =0;
if(m_m_m_>1000 && f_cont%1024==0)
mem_init(i_i_i_ +64);
/*************** *************** *************** **/
label:
if(bp+bp->s.size == p->s.ptr)/*lo unisce al blocco dopo*/
{bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
}
else bp->s.ptr=p->s.ptr;

if(p+p->s.size == bp)/* lo unisce al blocco prima*/
{p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
freep=r; R;
}
else p->s.ptr=bp;
freep = p;
}

void free_all_m(void ) {free_vettore_m (); free_list_m();}

/*Non usare free_all_m() ma free_a_i_m se ci sono oggetti
allocati da costruttori e distruttori del c++
(gli oggetti fuori da una qualsiasi procedura finiscono quando si
chiude
l'ultima istruzione del main) */
void free_a_i_mm(voi d)
{if(i_i_i_==0)
{free_vettore_m (); free_list_m();
if(stdout_m->flag)
P("MEMORIA DINAMICA LIBERATA Tot=%0f Mb\n",
((yuyuy*8.0)/1024000.0) );
}
else if( i_i_i_>=1 && p_p_p_!= 0 )
{if(stdout_m->flag)
P("Vi e' ancora da liberare 0x%p\n", (void*) p_p_p_[0]->p);
}
}

void free_a_i_m(void )
{if(i_i_i_==0 && show_si==0)
{free_vettore_m (); free_list_m();
if(stdout_m->flag)
P("MEMORIA DINAMICA LIBERATA Tot=%.4L Mb\n",
(long double) ((yuyuy*8.0)/1024000.0) );
show_si=1;
}
}
void free_a_r_m(void )
{if(i_i_i_==0)
{free_vettore_m (); free_list_m(); }
else if( i_i_i_>=1 && p_p_p_!= 0 && stdout_m->flag!=0)
{P("Vi e' ancora da liberare 0x%p\n", (void*)
p_p_p_[0]->p);}
}

void free_a_e_m(void )
{if(i_i_i_==0 && p_p_p_!=0)
{free_vettore_m (); free_list_m();
if(stdout_m->flag && p_p_p_==0)
{stato_mem();
P("Memoria libera\n");
}
}
else if( i_i_i_>=1 && p_p_p_!= 0 && stdout_m->flag)
{P("Vi e' ancora da liberare 0x%p\n", (void*)
p_p_p_[0]->p);}
}
/* morecore: chiede al sistema memoria aggiuntiva */
static Header* morecore(unsign ed nu)
{char *cp, **p;
Header *up;
unsigned len;
/*-----------------------*/
if(nu<NALLOC) nu=NALLOC;
// P("@@");
cp = (char*) malloc_sys(nu * sizeof(Header)) ;
// P("%u##", nu);
if( cp==0 ) /* non c'e' piu' spazio */
return NULL;

if(list_i_ >= list_m_ )
{len = (list_m_==0 ? 128: 2*list_m_);
if(list_==0) list_ = (char**) malloc_sys(4);
p = (char**) realloc_sys(lis t_, len * sizeof *p);
if(p==0) {free_sys(cp); return 0;}
list_ = p;
list_m_ =len;
}
list_[list_i_++]=cp;
up=(Header*) cp;
up->s.size=nu;
inserisci((void *)(up+1), 1, 0);
return freep;
}

/* se pointer!=0 ritorna la size del pointer
ritorna 0 se il pointer non c'e' */
unsigned get_size_m( void* pointer )
{int j;
/*----------------*/
if(pointer==0 || p_p_p_==0) R 0;
F(j=i_i_i_-1 ; j>=0 ; --j)
if( p_p_p_[j]->p == pointer ) break;
if(j<0) R 0;
R p_p_p_[j]->size;
}

void* realloc_m1(void *p, unsigned nbytes)
{unsigned j, k;
char *p1, *p2=(char*)p;
p1= (char*) malloc_m(nbytes );
if(p1==0) R 0;
k=get_size_m(p) ;
k = (k<=nbytes? k:nbytes);
F( j=0; j<k; ++j)
p1[j]=p2[j];
free_m(p);
R p1;
}

void* realloc_m(void *p, int nbytes)
{int k;
uns a, r, j, i;
char *p1, *p2;
if(nbytes<0) R 0;
k=get_size_m(p) ;
if(k<0) R 0;
p1= (char*) malloc_m(nbytes );
if(p1==0) R 0;
i = k<=nbytes? k: nbytes;
a=i/(sizeof(int)); r=i&(sizeof(int )-1);
F(j=0, p2=(char*)p; j<a; ++j)
((int*)p1)[j]=((int*)p2)[j];
F(i=4*j, r+=i; i<r; ++i)
p1[i]=p2[i];
free_m(p);
R p1;
}

void init_w(const char *nam)
{unsigned i, j;
/*---------------------*/
if(nam==0) R;
if( n_i_ 2 )
name_[n_i_ - 1]='|';
if( n_i_ >= 1016 ) // 0..14 carattere 15='|'
n_i_=0;
F(i=n_i_, j=0; j<15 && nam[j]!=0; ++i, ++j)
name_[i]=nam[j];
F( ; j< 15; ++i, ++j)
name_[i]=' ';
name_[i] = '#';
n_i_ += 16;
}

void leggi_mem(void)
{Header *u, *v;
unsigned j;
F( u = freep; u!=0 ; )
{P("|v=%u s=%u|", (unsigned)u / sizeof(Header), u->s.size );
if(u->s.ptr==freep ) break;
v=u->s.ptr;
if((u + u->s.size) != v)
{j = (uns)(v-u) - u->s.size;
if(j<123456)
P("%u", j );
else P("#");
}
u=v;
}
}

void stato_mem(void)
{unsigned j;
leggi_mem();
P("\nRAPPORTO MEMORIA DINAMICA. ");
P("Memoria richiesta al sistema=%.4f Mb ", ((yuyuy*8.0)/1024000.0) );
j=verifica_all_ m();
if(j!=0 && j!=-1)
{P("%u vettor%c allocat%c con successo\n",
j, j==1?'e':'i', j==1?'o':'i');
if( p_p_p_!= 0 && p_p_p_[0]!=0 )
{P("Vi e' ancora da liberare 0x%p\n", (void*)
p_p_p_[0]->p);}
}
else {if(j==0) {P("Out of bounds "); goto label;}
P("Il sistema non ha vettori da liberare ritornati da
malloc_m\n"); // j==-1
j=verifica_m(0, 0);
if(j==1) P("Sia la base sia il contatore sono NULLI\n");
else if(j==2) P("Il contatore e' nullo ma la base no\n");
else {label: ;
P("Errori nella memoria\n");
if(*memo_ && *name_)
P("memo=%s name=%s\n", memo_, name_ );
// free_vettore_m( ); free_list_m();
exit_m(1);
}
}
}

void controlla_m(cha r* st)
{P("!%s!", st);
if(verifica_all _m()==0)
{if(st) P("ERRORE!");
stato_mem();
}
}
/* free: inserisce in free list il blocco ap */
void free_m(void* ap)
{ int j, k;
/*-------------------*/
if(ap==0) R ;
if(libero_m_)
{if(verifica_al l_m()==0)
stato_mem();
}
if(k=verifica_m (ap, &j))
{ if(k==7)
{P("free_m(): ha cercato di liberare un puntatore che
non \n");
P("appartiene a quelli rilasciati da malloc_m: Esco...
\n");
}
else if(k==8 || k==9)
{P("free_m(): ha cercato di liberare un puntatore
\n");
P("in cui \"out of bound\" riscrittura. Esco... \n");
}
stato_mem();
// free_vettore_m( ); free_list_m();
exit_m(1);
}
inserisci(ap, 0, j);
}

void stampa_chiamate (void){P("memo= %s name=%s\n", memo_, name_ );}

Jan 27 '07 #1
52 3372
i would sai it is better
malloc(int a) than malloc(size_t a) or malloc(unsigned a)
because i can control if a<0 and in that case exit
Jan 27 '07 #2
¬a\/b wrote:
is it possible that a
malloc function that use a nobody student
is better than all yours :)

How many errors do you see?
Before we get into any substantive code,
#include <windows.h>
#include <winbase.h>
#include <wincon.h>
#include <winuser.h>
#include "winb.h"
All of the above are non-standard. Anything in the code that depends on
any of the above will not work outside of one specific proprietary
system. Post to a newsgroup for that OS, not here, but first check
their FAQs and prior postings. Your post may be beyond the size anyone
bothers with.

#define P printf
#define W while
#define F for
#define R return
To avoid being thought an illiterate fool, get rid of the above.
Jan 27 '07 #3
På Sat, 27 Jan 2007 07:26:28 -0000, skrev ¬a\/b <al@f.g>:
is it possible that a
malloc function that use a nobody student
is better than all yours :)
Much likly. This seems to me like _typical_ c.
C is used by most programmers, so it must be the best?
Therefore your code must be best.
I dont know c, so I cant confirm.

:)
Jan 27 '07 #4
Ico
In comp.lang.c "¬a\\/b" <al@f.gwrote:
is it possible that a
malloc function that use a nobody student
is better than all yours :)

How many errors do you see?
I didn't even bother to look, since my compiler found 46 already.

[snipped IOCCC-worthy code]

--
:wq
^X^Cy^K^X^C^C^C ^C
Jan 27 '07 #5
i would sai it is better
malloc(int a) than malloc(size_t a) or malloc(unsigned a)
because i can control if a<0 and in that case exit
not really. malloc with unsigned argument can have some upper-bound
defined (other than 7FFFFFFFh), and result is same.

Jan 27 '07 #6
#include <windows.h>
#include <winbase.h>
#include <wincon.h>
#include <winuser.h>
#include "winb.h"
All of the above are non-standard. Anything in the code that depends on
any of the above will not work outside of one specific proprietary
system. Post to a newsgroup for that OS, not here, but first check
their FAQs and prior postings. Your post may be beyond the size anyone
bothers with.
hey, don't be nazi. you NEED to call system to do memory management.
Point of this topic is to demonstrate his handler, and it is impossible
without. And it's enough to support one OS in demonstration, win32 is a
good choice because most asmers use it.
#define P printf
#define W while
#define F for
#define R return
oh god... don't be afraid of typing. also choose less obfuscative names
for your variables

Jan 27 '07 #7
"ï¿½ï¿½ï¿½ï¿½ï¿ ½ï¿½ï¿½ï¿½ï¿½ï¿ ½ï¿½ï¿½ï¿½ï¿½ï¿ ½ï¿½" wrote:
is it possible that a
malloc function that use a nobody student
is better than all yours :)

How many errors do you see?
My compiler shows 51 errors 17 warnings(is this a code :-p) apart from
the fact that all the headers are non-standard...so system specific..not
portable!
Jan 27 '07 #8
Martin Ambuhl <ma*****@earthl ink.netwrites:
¬a\/b wrote:
[snip]
#define P printf
#define W while
#define F for
#define R return

To avoid being thought an illiterate fool, get rid of the above.
We've been telling him that for years; it hasn't done any good.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 27 '07 #9
¬a\/b wrote:
is it possible that a
malloc function that use a nobody student
is better than all yours :)

How many errors do you see?
<sniped code eligible for ioccc.org>

This group (comp.lang.c), doesn't discuss details of implementation.
Since you appear to be targetting the Windows platform, post to a
Windows group. It's also not topical for alt.lang.asm.

Jan 27 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2790
by: Ruslan Vorobey | last post by:
Hi All. Does anybody saw any C++ new operator implementations? I need just to know does it use malloc? Especially I interesting about standard C++ libs implementation under AIX 5.1L. Thank you in advance.
12
7597
by: Anil | last post by:
Hi, Where can I get the source code that has the implementation of the below C operators/functions: malloc sizeof new strcmp strtok
8
1690
by: farhanb | last post by:
hello, I am writing a simple linked list implementation. When I use function insert1 I must allocate to head in my main to get it to work otherwise list stays empty but when I use function insert2 there is no need to allocate to head this is the correct way. why does this happen? why do we need to have a pointer to a pointer to head in the insert function for this to work?
14
1847
by: Henk | last post by:
Hi Guys, (see actual code below) I wrote a little program that is supposed to read a file (input.txt) into memory (using a stack) and then reverse the file and display it to output. It works, but I still get some errors when i try to compile it: stack.c: In function 'reverseFile'
49
23168
by: Karsten Jung | last post by:
Hello together, We have to make our own implementation of malloc() under Linux. Does anybody can give me a hint where to start? Our implementation should only work under Linux. Thanks Karsten
41
3329
by: jacob navia | last post by:
In the C tutorial for lcc-win32, I have a small chapter about a debugging implementation of malloc. Here is the code, and the explanations that go with it. I would appreciate your feedback both about the code and the associated explanations. ---------------------------------------------------------------------
14
1379
by: Army1987 | last post by:
#include <string.h> #include <stdlib.h> #include <stdio.h> char *_(char *str1, char *str2) { char *res; res = malloc((strlen(str1)+strlen(str2))*sizeof(char)); strcpy(res, str1); strcpy(res+strlen(str1), str2); return res;
27
5536
by: Kislay | last post by:
How is realloc implemented internally ? If there is not enough memory in place to allocate , is new memory allocated somewhere else and the 2 regions linked via a pointer , OR , is the old region copied to a place where there is enough memory to fit both old and new region ? In the second case , wouldn't this method be inefficient if the old region was large ?
3
3513
by: C++Liliput | last post by:
Hi, I was looking at the implementation of operator new and operator new in gcc source code and found that the implementation is exactly the same. The only difference is that the size_t argument passed to the operators is calculated correctly during runtime and passed in. Inside the implementation both operators (new and new) do a simple malloc(). Ditto for operator delete/delete. I have two questions: 1) Who passes in the size_t argument...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.