- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to storedata to a file for saving memory, but the program uses more memory to read and write data. Here is a example, the program creates 400 MB memoryfor reading and writing. After the array is deallocated and the file is closed, there are still 200MB memory in the program.
!-------------------------------------------------
program test
implicit none
complex(8),pointer::A(:)
integer::N,i
open(1,file="test.txt",form='unformatted')
N=13000000
!2 MB
allocate(A(N))
!2 MB
do i=1,N
A(i)=real(i)
end do
!205 MB
write(1)A
!409 MB
rewind(1)
read(1)A
!613MB
deallocate(A)
!409 MB
close(1,status='delete')
!206 MB
end program test
implicit none
complex(8),pointer::A(:)
integer::N,i
open(1,file="test.txt",form='unformatted')
N=13000000
!2 MB
allocate(A(N))
!2 MB
do i=1,N
A(i)=real(i)
end do
!205 MB
write(1)A
!409 MB
rewind(1)
read(1)A
!613MB
deallocate(A)
!409 MB
close(1,status='delete')
!206 MB
end program test
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Deallocated memory generally does not cause the virtual memory used by a running program to decrease - that memory is in a pool available for future allocations, but the OS believes it is in use.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. sblionel!
My question is why the program creats memory for reading and writing. It makesmy computer need more memory to run. If my computer doen't hasenough physical memory, the disk will be used for swapping and it will run slowly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the run-time library allocates its own buffer for the record.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page