- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CVF 6B
win2k Pro SP3
Intel P3
The following code (as a console app) seems to work fine.
It is a method for creating equivalence on an allocatable array which is passed to a module routine.
I am using the same concept in a (in process) COM DLL where the 2D (target) array size is about 7000x10.
Somewhere in the middle of the run (apparently depending on the virual memory size) I get the windows error "Low on virtual memory". After this windows terminates the whole application.
I used to have the pointer and the target arrays as regular arrays and simple copies of each other.
I thought that the pointer idea would (if anything) cut down on memory usage a little.
I seem to skip the error if the declaration and pointing are done but no other reference is made to either the pointer or the target.
Any clues as to
1.why I'm getting the error.
2. How to fix it or if there is a better way
3. or if this is NOT a good idea and I should go back to TWO separate copies of data.
Will be appreciated.
Tim
----------------------------------------------------------
module m
real, allocatable, target:: z(:,:)
contains
subroutine in(x,I,J)
integer i,j
real,intent(in):: x(i,j)
real, pointer:: zz1(:),zz2(:)
allocate(z(i,j))
z=x
allocate(zz1(i),zz2(i))
zz1=>z(:,1)
zz2=>z(:,2)
print *, 'zz1,zz2 =',zz1,zz2
z1=3; z2=4
print *, 'zz1=',zz1,'zz2=',zz2
end subroutine in
end module m
!--------------------------------------------
use m
real x(2,2)
x(:,1)=1.
x(:,2)=2.
call in(x,2,2)
pause
end
!------------------------------------------
win2k Pro SP3
Intel P3
The following code (as a console app) seems to work fine.
It is a method for creating equivalence on an allocatable array which is passed to a module routine.
I am using the same concept in a (in process) COM DLL where the 2D (target) array size is about 7000x10.
Somewhere in the middle of the run (apparently depending on the virual memory size) I get the windows error "Low on virtual memory". After this windows terminates the whole application.
I used to have the pointer and the target arrays as regular arrays and simple copies of each other.
I thought that the pointer idea would (if anything) cut down on memory usage a little.
I seem to skip the error if the declaration and pointing are done but no other reference is made to either the pointer or the target.
Any clues as to
1.why I'm getting the error.
2. How to fix it or if there is a better way
3. or if this is NOT a good idea and I should go back to TWO separate copies of data.
Will be appreciated.
Tim
----------------------------------------------------------
module m
real, allocatable, target:: z(:,:)
contains
subroutine in(x,I,J)
integer i,j
real,intent(in):: x(i,j)
real, pointer:: zz1(:),zz2(:)
allocate(z(i,j))
z=x
allocate(zz1(i),zz2(i))
zz1=>z(:,1)
zz2=>z(:,2)
print *, 'zz1,zz2 =',zz1,zz2
z1=3; z2=4
print *, 'zz1=',zz1,'zz2=',zz2
end subroutine in
end module m
!--------------------------------------------
use m
real x(2,2)
x(:,1)=1.
x(:,2)=2.
call in(x,2,2)
pause
end
!------------------------------------------
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why do you allocate zz1 and zz2? I ask because the very next thing you do is point them at sections of z, thus leaking the memory that was allocated.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hot Dawg!
I thought I read somewhere that pointer must ALWAYS be allocated.
So you are saying that I do not need to allocate the pointers to point them to the target?
I will try it and post the result.
Tim
I thought I read somewhere that pointer must ALWAYS be allocated.
So you are saying that I do not need to allocate the pointers to point them to the target?
I will try it and post the result.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A pointer is just that, a pointer. It can point to storage that you allocated separately (which is what you want to do), or you can allocate new storage it should point to (the ALLOCATE statement). Pointer assignment is like a forwarding address, and wipes out any previous information in the pointer.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks,
Would you say that the pointer (ZZ) should be declared with (:) or (explicit size)?
Tim
Would you say that the pointer (ZZ) should be declared with (:) or (explicit size)?
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(I assume you mean ZZ1 and ZZ2 - you don't have a ZZ.) You don't have a choice here - (:) is correct. The bounds get filled in when you do the pointer assignment.
Steve
Steve

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