gds@spam.istc.sri.com (Greg Skinner) (05/01/89)
I am having problems finding the right routine to free storage allocated for a handle I have created, and the THINK Pascal documentation is not clear on how to do this. Here is a code fragment: program foo; type vec = array [1..10000] of integer; vecptr = ^vec; vechandle = ^vecptr; procedure bar (var A: vechandle; k: integer); var B, C: vechandle; begin B := vechandle(NewHandle(k * sizeof(integer))); C := vechandle(NewHandle(k * sizeof(integer))); [...] (* code to free space for B and C goes here *) end; I am getting run-time errors when I try to do a dispose(vechandle(B)); and I cannot find any other way of freeing the storage. Please mail your response. thanks, --gregbo
gds@spam.istc.sri.com (Greg Skinner) (05/07/89)
I wanted to thank everyone for their help. There were a few questions about some specific code I wrote, namely: > begin > B := vechandle(NewHandle(k * sizeof(integer))); > C := vechandle(NewHandle(k * sizeof(integer))); > [...] > (* code to free space for B and C goes here *) > end; I did not want to allocate space for the whole array, which was 10000 locations, because that would have run my machine out of memory. (This block is in a recursive call.) Instead, I only wished to allocate space for as much as I needed for an array of that type. Thus, the "k". Since I am a C programmer, I am used to dealing with pointers and allocating as much space as I need, rather than allocating all the space that is declared for a variable of that type. This is probably not such a good way to do things, as the Pascal compiler may not allow you to allocate space in that manner. (I don't know -- this is one of my problems, dealing with a nonstandard compiler in a language and programming environment I am not comfortable with.) Thanks for all your help, anyway. --gregbo