Ignore:
Timestamp:
Mar 22, 2008, 10:39:25 AM (12 years ago)
Author:
Sam Hocevar
Message:
  • Get rid of jmalloc and replace it with standard malloc. Modern operating systems certainly perform a lot better than this custom implementation, and we have superior tools (eg. valgrind) to debug and profile memory usage without interfering with the code itself.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/level.cpp

    r124 r129  
    7676void level::load_fail()
    7777{
    78   if (map_fg)    jfree(map_fg);   map_fg=NULL;
    79   if (map_bg)    jfree(map_bg);   map_bg=NULL;
    80   if (Name)      jfree(Name);     Name=NULL;
     78  if (map_fg)    free(map_fg);   map_fg=NULL;
     79  if (map_bg)    free(map_bg);   map_bg=NULL;
     80  if (Name)      free(Name);     Name=NULL;
    8181
    8282  first_active=NULL;
     
    111111{
    112112  load_fail();
    113   if (attack_list) jfree(attack_list);
    114   if (target_list) jfree(target_list);
    115   if (block_list) jfree(block_list);
    116   if (all_block_list) jfree(all_block_list);
    117   if (first_name) jfree(first_name);
     113  if (attack_list) free(attack_list);
     114  if (target_list) free(target_list);
     115  if (block_list) free(block_list);
     116  if (all_block_list) free(all_block_list);
     117  if (first_name) free(first_name);
    118118}
    119119
     
    835835
    836836  uint16_t *new_fg,*new_bg;
    837   new_fg=(uint16_t *)jmalloc(w*h*sizeof(int16_t),"Map fg : resized");
     837  new_fg=(uint16_t *)malloc(w*h*sizeof(int16_t));
    838838  memset(new_fg,0,w*h*sizeof(int16_t));
    839839
     
    843843  calc_bgsize(w,h,nbw,nbh);
    844844
    845   new_bg=(uint16_t *)jmalloc((int)nbw*(int)nbh*sizeof(int16_t),"map bg : resized");
     845  new_bg=(uint16_t *)malloc((int)nbw*(int)nbh*sizeof(int16_t));
    846846  memset(new_bg,0,(int)nbw*(int)nbh*sizeof(int16_t));
    847847
     
    857857      new_bg[x+y*nbw]=get_bg(x,y);
    858858
    859   jfree(map_fg);
    860   jfree(map_bg);
     859  free(map_fg);
     860  free(map_bg);
    861861  map_fg=new_fg;
    862862  map_bg=new_bg;
     
    898898    /******************************* Read debug info ******************************/
    899899    int16_t old_tot=fp->read_uint16();
    900     uint16_t *o_remap=(uint16_t *)jmalloc(old_tot*2,"obj remap array");
     900    uint16_t *o_remap=(uint16_t *)malloc(old_tot * 2);
    901901    char old_name[150];
    902902    for (i=0;i<old_tot;i++)
     
    913913    /***************************** Read state names *********************************/
    914914    int old_stot=fp->read_uint16();
    915     unsigned char *s_remap=(unsigned char *)jmalloc(old_stot,"state remap array");
     915    unsigned char *s_remap=(unsigned char *)malloc(old_stot);
    916916    for (i=0;i<old_stot;i++)
    917917    {
     
    10051005    }
    10061006
    1007 
    1008 
    1009     jfree(o_remap);
    1010     jfree(s_remap);
     1007    free(o_remap);
     1008    free(s_remap);
    10111009  }
    10121010
     
    10341032      return ;
    10351033
    1036     uint16_t *o_remap=(uint16_t *)jmalloc(old_tot*2,"obj remap array");
    1037     uint16_t *o_backmap=(uint16_t *)jmalloc(total_objects*2,"obj remap array");
     1034    uint16_t *o_remap=(uint16_t *)malloc(old_tot * 2);
     1035    uint16_t *o_backmap=(uint16_t *)malloc(total_objects * 2);
    10381036    memset(o_backmap,0xff,total_objects*2);
    10391037    char old_name[150];
     
    10521050
    10531051    se=sd->find("describe_states");
    1054     if (!se) { jfree(o_remap); jfree(o_backmap); return ; }
    1055     int16_t **s_remap=(int16_t **)jmalloc(old_tot*sizeof(int16_t *),"big state remap array");
    1056     int16_t *s_remap_totals=(int16_t *)jmalloc(old_tot*sizeof(int16_t),"big state rmp totals");
     1052    if (!se) { free(o_remap); free(o_backmap); return ; }
     1053    int16_t **s_remap=(int16_t **)malloc(old_tot*sizeof(int16_t *));
     1054    int16_t *s_remap_totals=(int16_t *)malloc(old_tot*sizeof(int16_t));
    10571055    fp->seek(se->offset,0);
    10581056    int i=0;
     
    10631061      if (t)
    10641062      {
    1065         s_remap[i]=(int16_t *)jmalloc(t*sizeof(int16_t),"state remap");
     1063        s_remap[i]=(int16_t *)malloc(t*sizeof(int16_t));
    10661064    int j=0;
    10671065    for (;j<t;j++)
     
    10941092    if (se)
    10951093    {
    1096       v_remap=(int16_t **)jmalloc(old_tot*sizeof(int16_t *),"big var remap array");
    1097       v_remap_totals=(int16_t *)jmalloc(old_tot*sizeof(int16_t),"big var rmp totals");
     1094      v_remap=(int16_t **)malloc(old_tot*sizeof(int16_t *));
     1095      v_remap_totals=(int16_t *)malloc(old_tot*sizeof(int16_t));
    10981096
    10991097      fp->seek(se->offset,0);
     
    11051103    if (t)
    11061104    {
    1107       v_remap[i]=(int16_t *)jmalloc(t*sizeof(int16_t),"var remap");
     1105      v_remap[i]=(int16_t *)malloc(t*sizeof(int16_t));
    11081106      memset(v_remap[i],0xff,t*sizeof(int16_t));
    11091107    } else { v_remap[i]=NULL; }
     
    12561254    {
    12571255      if (s_remap_totals[k])
    1258         jfree(s_remap[k]);
     1256        free(s_remap[k]);
    12591257    }
    12601258
     
    12631261    {
    12641262      if (v_remap_totals[l])
    1265         jfree(v_remap[l]);
    1266     }
    1267     jfree(v_remap_totals);
    1268     jfree(s_remap_totals);
    1269     jfree(o_remap);
    1270     jfree(o_backmap);
    1271     jfree(s_remap);
    1272     jfree(v_remap);
     1263        free(v_remap[l]);
     1264    }
     1265    free(v_remap_totals);
     1266    free(s_remap_totals);
     1267    free(o_remap);
     1268    free(o_backmap);
     1269    free(s_remap);
     1270    free(v_remap);
    12731271  }
    12741272
     
    12981296  sprintf(cmd,symbol_str("loading"),lev_name);
    12991297  stack_stat stat(cmd);
    1300   Name=strcpy((char *)jmalloc(strlen(lev_name)+1,"lev name"),lev_name);
     1298  Name=strcpy((char *)malloc(strlen(lev_name)+1),lev_name);
    13011299
    13021300  e=sd->find("first name");
     
    13051303    fp->seek(e->offset,0);
    13061304    int len=fp->read_uint8();   // read the length of the string
    1307     first_name=(char *)jmalloc(len,"level first name");
     1305    first_name=(char *)malloc(len);
    13081306    fp->read(first_name,len);    // read the string
    13091307  } else
    13101308  {
    1311     first_name=(char *)jmalloc(strlen(Name)+1,"level first name");
     1309    first_name=(char *)malloc(strlen(Name)+1);
    13121310    strcpy(first_name,Name);
    13131311  }
     
    13211319    fg_width=fp->read_uint32();
    13221320    fg_height=fp->read_uint32();
    1323     map_fg=(uint16_t *)jmalloc(2*fg_width*fg_height,"Map fg : loaded");
     1321    map_fg=(uint16_t *)malloc(2*fg_width*fg_height);
    13241322    fp->read((char *)map_fg,2*fg_width*fg_height);
    13251323    int t=fg_width*fg_height;
     
    13391337    bg_width=fp->read_uint32();
    13401338    bg_height=fp->read_uint32();
    1341     map_bg=(uint16_t *)jmalloc(2*bg_width*bg_height,"Map bg : loaded");
     1339    map_bg=(uint16_t *)malloc(2*bg_width*bg_height);
    13421340    fp->read((char *)map_bg,2*bg_width*bg_height);
    13431341    int t=bg_width*bg_height;
     
    13541352    fg_width=bg_width;
    13551353    fg_height=bg_height;
    1356     map_fg=(uint16_t *)jmalloc(2*fg_width*fg_height,"Map fg : loaded");
     1354    map_fg=(uint16_t *)malloc(2*fg_width*fg_height);
    13571355    memset(map_fg,0,2*fg_width*fg_height);
    13581356  }
     
    13621360    bg_width=fg_width/8+8;
    13631361    bg_height=fg_height/8+8;
    1364     map_bg=(uint16_t *)jmalloc(2*bg_width*bg_height,"Map bg : loaded");
     1362    map_bg=(uint16_t *)malloc(2*bg_width*bg_height);
    13651363    memset(map_bg,0,2*bg_width*bg_height);
    13661364  }
     
    22172215            else
    22182216            {
     2217                uint8_t buf[0x1000];
    22192218                int32_t size = fp->file_size();
    2220                 uint8_t *buf = (uint8_t *)jmalloc(0x1000,"copy buf");
    22212219                int tr = 1;
    22222220                while( size && tr )
     
    22272225                    size -= tr;
    22282226                }
    2229                 jfree(buf);
    22302227            }
    22312228            delete bk;
     
    22412238    {
    22422239        if( first_name )
    2243             jfree(first_name);
    2244         first_name = (char *)jmalloc( strlen( name ) + 1, "level first name" );
     2240            free(first_name);
     2241        first_name = (char *)malloc( strlen( name ) + 1 );
    22452242        strcpy( first_name, name );
    22462243    }
     
    23812378  calc_bgsize(fg_width,fg_height,bg_width,bg_height);
    23822379
    2383   map_bg=(uint16_t *)jmalloc(sizeof(int16_t)*bg_width*bg_height,"map bg");
    2384   map_fg=(uint16_t *)jmalloc(sizeof(int16_t)*fg_width*fg_height,"map fg");
     2380  map_bg=(uint16_t *)malloc(sizeof(int16_t)*bg_width*bg_height);
     2381  map_fg=(uint16_t *)malloc(sizeof(int16_t)*fg_width*fg_height);
    23852382
    23862383
     
    31173114  {
    31183115    attack_list_size++;
    3119     attack_list=(game_object **)jrealloc(attack_list,sizeof(game_object *)*attack_list_size,
    3120                               "attack_list");
     3116    attack_list=(game_object **)realloc(attack_list,sizeof(game_object *)*attack_list_size);
    31213117  }
    31223118  attack_list[attack_total]=who;
     
    31313127  {
    31323128    target_list_size++;
    3133     target_list=(game_object **)jrealloc(target_list,sizeof(game_object *)*target_list_size,
    3134                               "target_list");
     3129    target_list=(game_object **)realloc(target_list,sizeof(game_object *)*target_list_size);
    31353130  }
    31363131  target_list[target_total]=who;
     
    31453140  {
    31463141    block_list_size++;
    3147     block_list=(game_object **)jrealloc(block_list,sizeof(game_object *)*block_list_size,
    3148                               "block_list");
     3142    block_list=(game_object **)realloc(block_list,sizeof(game_object *)*block_list_size);
    31493143  }
    31503144  block_list[block_total]=who;
     
    31583152  {
    31593153    all_block_list_size++;
    3160     all_block_list=(game_object **)jrealloc(all_block_list,sizeof(game_object *)*all_block_list_size,
    3161                               "all_block_list");
     3154    all_block_list=(game_object **)realloc(all_block_list,sizeof(game_object *)*all_block_list_size);
    31623155  }
    31633156  all_block_list[all_block_total]=who;
Note: See TracChangeset for help on using the changeset viewer.