1. allocate & free
- Posted by irvm at ellijay.com Dec 10, 2001
- 408 views
Hi: I must not be using allocate() and/or free() correctly: Here's the code, which, if the --// comment is removed, will fill a list control: (that part works fine) for i = 1 to db_table_size() do data = db_record_data(i) len = length(data)+1 addresses = allocate(len*4) poke4(addresses,allocate_string(db_record_key(i))) for j = 1 to length(data) do if atom(data[j]) then data[j] = sprintf("%g",data[j]) -- change numeric fields to text end if poke4(addresses+j*4,allocate_string(data[j])) end for --// ok = gtk_clist_append(list,addresses) free(addresses) end for Problem is, each time this is run, extra memory is used, corresponding to the length of the data loaded. Eventually, I would run out of menory. It does the same whether or not the call to gtk_list_append() is made, so that's not the problem. That leaves free(). Am I not using it correctly? Thanks for any help, Irv
2. Re: allocate & free
- Posted by euman at bellsouth.net Dec 10, 2001
- 437 views
Hi Irv, Look like your not free'ing any of the allocated_strings. Another intersting piece to this is you're reading in from a file-based DB to a so-called Mem-Based DB of sorts. Matt L. put up some interesting code in his EuDLL project a while back. Take a look at the sequence.ew file You could get away with not having to use external file-based but instead include the sequences in your program and use his tool to form compressed sequences in memory much the same way EDS functions on files. Just a thought! Euman euman at bellsouth.net ----- Original Message ----- From: <irvm at ellijay.com> To: "EUforum" <EUforum at topica.com> Sent: Monday, December 10, 2001 1:36 PM Subject: allocate & free > > > Hi: > > I must not be using allocate() and/or free() correctly: > Here's the code, which, if the --// comment is removed, will > fill a list control: (that part works fine) > > for i = 1 to db_table_size() do > > data = db_record_data(i) > len = length(data)+1 > addresses = allocate(len*4) > > poke4(addresses,allocate_string(db_record_key(i))) > > for j = 1 to length(data) do > if atom(data[j]) then > data[j] = sprintf("%g",data[j]) -- change numeric fields to text > end if > poke4(addresses+j*4,allocate_string(data[j])) > end for > > --// ok = gtk_clist_append(list,addresses) > > free(addresses) > > end for > > Problem is, each time this is run, extra memory is used, corresponding to the > length of the data loaded. Eventually, I would run out of menory. It does the > same whether or not the call to gtk_list_append() is made, so that's not the > problem. That leaves free(). Am I not using it correctly? > > Thanks for any help, > Irv > > > >