home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3210 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.3 KB  |  59 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!mcsun!news.funet.fi!cc.tut.fi!koski
  3. From: koski@cc.tut.fi (Koski Aapo)
  4. Subject: Dynamic memory allocation in F77
  5. Message-ID: <1992Aug27.084750.2892@cc.tut.fi>
  6. Organization: Tampere University of Technology, Finland
  7. Date: Thu, 27 Aug 92 08:47:50 GMT
  8. Lines: 48
  9.  
  10.  
  11.  
  12. Hi,
  13.  
  14. We are trying to use a dynamic memory allocator written in C with
  15. FORTRAN main program. The allocator looks like this:
  16.  
  17. void C_ALLOCATE(size,ptr)
  18. int *size;
  19. char **ptr;
  20. {
  21.   *ptr = (char *)malloc((unsigned)(*size));
  22.   if (*ptr==NULL) *size=0;
  23.   else {
  24.     memset(*ptr,'\0',*size);
  25.   }
  26. }
  27.  
  28.  
  29. And the program to free the allocated memory:
  30.  
  31. void C_FREE(ptr)
  32. char **ptr;
  33. {
  34.   free(*ptr);
  35. }
  36.  
  37.  
  38. The memory for arrays is allocated in main program and memory
  39. addresses are passed to subroutines with reference %Ref. The
  40. memory is allocated OK with this routine above and we are able
  41. to write into the allocated memory area.
  42.  
  43. When debugging the memory immediatly after the assignment statement
  44. the memory block contains right value, but after a while something
  45. changes the data. 
  46.  
  47. It seems to me, that the allocated memory block is not reserved. Is
  48. something able to write on this block after allocation ?
  49.  
  50. The hardware & software we're using:
  51.  
  52.     Stardent 3000
  53.     TitanOS 4.1 and it's F77 & C compilers
  54.  
  55.  
  56. Any information on this topic is appreciated
  57.  
  58.     - Aapo Koski
  59.