- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Everyone and thank you for your time in advance;
My problem is in a DLL function to which I am sending in the dimensions of some matrices as arguments (NROW and NCOL). If I initialize the matrices as follows
I don't get any problems whereas if the above excerpt is changed to
Calling the function with any number greater than 250 or so results in an "unknown software exception" !! error, i.e. the call "catchflow.Call({1000, 1000})" fails for the second case.
I'll appreciate any help to clarify this problem.
Greetings
Derya
My problem is in a DLL function to which I am sending in the dimensions of some matrices as arguments (NROW and NCOL). If I initialize the matrices as follows
!DEC$ ATTRIBUTES C, DLLEXPORT :: PHASEONE INTEGER FUNCTION PHASEONE(NROW, NCOL) ... REAL ELEV(2000,2000), SCT(2000,2000) ...
I don't get any problems whereas if the above excerpt is changed to
!DEC$ ATTRIBUTES C, DLLEXPORT :: PHASEONE INTEGER FUNCTION PHASEONE(NROW, NCOL) ... REAL ELEV(NROW,NCOL), SCT(NROW,NCOL) ...
Calling the function with any number greater than 250 or so results in an "unknown software exception" !! error, i.e. the call "catchflow.Call({1000, 1000})" fails for the second case.
I'll appreciate any help to clarify this problem.
Greetings
Derya
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your arrays are "automatic arrays", which means they are local variables allocated on the stack. The stack has a fixed size determined when the executable is linked, which in this case, is whatever you are calling the DLL from (I don't recognize the syntax you're using). What that means is - you probably can't change the size.
Consider this alternative:
This will accomplish the goal of having a run-time sized array, and you won't be limited by the stack size, since the arrays will be allocated from the heap. They will get deallocated automatically when PHASEONE exits.
Incidentally, I am not comfortable with having the ATTRIBUTES directive BEFORE the FUNCTION statement. I am not sure if this really works (I'd have to run some tests) - the more common usage is to have the directive after the FUNCTION or SUBROUTINE statement.
Steve
Consider this alternative:
INTEGER FUNCTION PHASEONE (NROW, NCOL) REAL, ALLOCATABLE :: ELEV(:,:), SCT (:.:) ... ALLOCATE (ELEV(NROW,NCOL),SCT(NROW,NCOL)) ...
This will accomplish the goal of having a run-time sized array, and you won't be limited by the stack size, since the arrays will be allocated from the heap. They will get deallocated automatically when PHASEONE exits.
Incidentally, I am not comfortable with having the ATTRIBUTES directive BEFORE the FUNCTION statement. I am not sure if this really works (I'd have to run some tests) - the more common usage is to have the directive after the FUNCTION or SUBROUTINE statement.
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can somebody give me a brief explanation of what the stack and heap are? They appear to be two different pools of memory that a program can use, and their sized appear to be governed by different limits.
Mike
Mike
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
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