home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!mcsun!news.funet.fi!cc.tut.fi!koski
- From: koski@cc.tut.fi (Koski Aapo)
- Subject: Dynamic memory allocation in F77
- Message-ID: <1992Aug27.084750.2892@cc.tut.fi>
- Organization: Tampere University of Technology, Finland
- Date: Thu, 27 Aug 92 08:47:50 GMT
- Lines: 48
-
-
-
- Hi,
-
- We are trying to use a dynamic memory allocator written in C with
- FORTRAN main program. The allocator looks like this:
-
- void C_ALLOCATE(size,ptr)
- int *size;
- char **ptr;
- {
- *ptr = (char *)malloc((unsigned)(*size));
- if (*ptr==NULL) *size=0;
- else {
- memset(*ptr,'\0',*size);
- }
- }
-
-
- And the program to free the allocated memory:
-
- void C_FREE(ptr)
- char **ptr;
- {
- free(*ptr);
- }
-
-
- The memory for arrays is allocated in main program and memory
- addresses are passed to subroutines with reference %Ref. The
- memory is allocated OK with this routine above and we are able
- to write into the allocated memory area.
-
- When debugging the memory immediatly after the assignment statement
- the memory block contains right value, but after a while something
- changes the data.
-
- It seems to me, that the allocated memory block is not reserved. Is
- something able to write on this block after allocation ?
-
- The hardware & software we're using:
-
- Stardent 3000
- TitanOS 4.1 and it's F77 & C compilers
-
-
- Any information on this topic is appreciated
-
- - Aapo Koski
-