 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
FLEXPLAN3D
Joined: 25 Feb 2011 Posts: 27
|
Posted: Mon Feb 28, 2011 1:10 pm Post subject: get_filtered_file@ and large array |
|
|
Since moving to Windows 7, I have had problems with get_filtered_file@
when used in programs with large arrays (typically 500mbytes).
The dialigue box open ok, with all the filters set, set correctly. But, I find the edit box into which the file name is entered locks up when the <cr> key is pressed.
It makes no differnece wether the array is declared in common or the allocate command is used to set the array size.
I see from the forum that others are experincing problems wth large arrays. Does anyone els have this problem.
Here is the code
MODULE DATA32
INTEGER*4, DIMENSION( ,ALLOCATABLE::DATA
END MODULE DATA32
USE DATA32
WINAPP
PARAMETER(MBYTES=700)
PARAMETER(MILLION=1000000)
CHARACTER file*129,title*20,path*129
INTEGER NFILTERS
PARAMETER(NFILTERS=1)
CHARACTER*20 filtname(NFILTERS),filtspec(NFILTERS)
c------------------------------------
C*** allocate mbytes to array data
ALLOCATE(DATA(MBYTES*MILLION/4),STAT=istatus)
IF(ISTATUS.NE.0)STOP 'CANT ALLOCATE MEMORY'
c*** populate array
do j=1,mbytes*million/4
data(j)=j
enddo
C**** Use clearwin - get_filtered_file
title='Open Bitmap File'
file=' '
path=' '
filtname(1)='All files'
filtspec(1)='*.*'
CALL get_filtered_file@(title,file,path,filtname,filtspec,
* NFILTERS,1)
END |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Tue Mar 01, 2011 1:54 pm Post subject: |
|
|
On Windows 7 Home Premium X64, your program runs fine when compiled with FTN95 6.0. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Tue Mar 01, 2011 5:15 pm Post subject: |
|
|
Try removing all references to the data array first.
Just call get_filtered_file@ and increase the number of characters in file and path to 256. |
|
Back to top |
|
 |
FLEXPLAN3D
Joined: 25 Feb 2011 Posts: 27
|
Posted: Tue Mar 01, 2011 9:12 pm Post subject: |
|
|
Thanks for the suggestions which I have followed up.
I have tried it now with version 6, and also made the changes Paul suggested but get the same problem once the array exceeds about 500mega bytes. As before all is ok below this size.
The problem is not with get_filtered file as such as I have tried replacing it with the api call getopenfilename.
I have also used c code to allocate a block of memory with the globalloc function which gets memory from the heap, and the problem is still there once the memory requested exceeds about 500mbytes.
I have also tried putting the get_filtered_ file call in a DLL to no availl.
The only way I can get it work is to put the get_filtered_file call in a separate application and use winexec to executes it, but this is a meesy solution.
I just wondered if any one out there can reproduce the problem. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Wed Mar 02, 2011 12:14 am Post subject: |
|
|
I tried your code on XP x64 professional and FTN95 Ver 5.50 and had no problems. I modified your code slightly but could not identify the source of your error.
I modified ALLOCATE, but the change is probably not required.
FILE*129 should only have to be increased if the file(tree) name exceeded 129 characters. I even tried FILE*25 and the program ran successfully.
I would not expect the error you are reporting.
Code: | MODULE DATA32
INTEGER*4, DIMENSION(:),ALLOCATABLE :: DATA
END MODULE DATA32
USE DATA32
! WINAPP ! this is probably not needed
integer*4, PARAMETER :: MBYTES = 700
integer*4, PARAMETER :: MILLION = 1000000
integer*4, PARAMETER :: NFILTERS= 2
!
CHARACTER file*256, title*20, path*20
CHARACTER*20 filtname(NFILTERS), filtspec(NFILTERS)
integer*4 istatus, j, n
!
!------------------------------------
!*** allocate mbytes to array data
n = MBYTES*MILLION/4
ALLOCATE (DATA(n),STAT=istatus)
IF (ISTATUS.NE.0) STOP 'CANT ALLOCATE MEMORY'
write (*,fmt='(a,i0,a)') 'Array DATA(',n,') allocated'
!
!*** populate array
do j=1,n
data(j)=j
end do
!
!**** Use clearwin - get_filtered_file
title = 'Open Bitmap File'
file = ' '
path = ' '
filtname(1) = 'Bitmap files'
filtspec(1) = '*.bmp'
filtname(2) = 'All files'
filtspec(2) = '*.*'
CALL get_filtered_file@ (title, file, path, filtname, filtspec, NFILTERS, 1)
write (*,*) 'File ',trim(file),' selected'
!
END |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Wed Mar 02, 2011 10:07 am Post subject: |
|
|
It seems that the common "Open" dialog box can use large amounts of memory just to store its own data for all of the folders etc. This kind of problem as been reported a number of times over the years and to my mind there has never been a satisfactory explanation or solution. There ought to be plenty of memory available but for some unknown reason there is a conflict between what the Microsoft dll is doing and the Fortran executable.
The problem apears to occur in a random fashion across various operating systems. |
|
Back to top |
|
 |
FLEXPLAN3D
Joined: 25 Feb 2011 Posts: 27
|
Posted: Thu Mar 03, 2011 10:59 am Post subject: |
|
|
Paul
Thanks for your comments.
I have found that the problem has nothing to do with the Fortran Compiler as I can reproduce the problem using the Silverfrost C++ compiler.
I have also used exactly the same code in Microsoft Visual Studio, and the problem did not occur (i.e. the keyboard did not lock up when pressing the <enter> key at the end of the filename). Further I was able to allocate 1.3gbytes of memory with Visual Studio compared with 500mbytes for Silverfrost.
Here is the code used with both c++ compilers.
// for silverfrost compile and link with
// c:\win32app\salford\scc memtest.c /prototypes /ansi_c /no_line /windows /lgo
//for visual studio used IDE.
#include <windows.h>
#include <commdlg.h>
LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int);
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HGLOBAL status;
OPENFILENAME ofn;
char banner[256] =" Visual Studio openfile test ";
char filter[256] ="all files\0*.*\0";
char filename[256],dirname[256];
filename[0]='\0';
dirname[0]='\0';
int memsize;
/* grab some memory */
// Visual Studio will get up to 1.3gb, Silverfrost will get up to 500mb)
memsize=1300 * 1000000;
status= GlobalAlloc(GMEM_FIXED,memsize);
if(status == NULL)MessageBox(0," Cant allocate memory",NULL,MB_OK);
/*open file*/
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrFilter = filter;
ofn.nFilterIndex=1;
ofn.lpstrFile=filename;
ofn.nMaxFile=256;
ofn.lpstrInitialDir = dirname;
ofn.lpstrTitle=banner;
ofn.Flags= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ;
GetOpenFileName(&ofn);
return 0;
}
LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
return DefWindowProc(hWnd,message,wParam,lParam) ;
}
} |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Thu Mar 03, 2011 11:41 am Post subject: |
|
|
I should have been more specific. Its not so much the Fortran compiler but the linker that is common to SCC and FTN95.
The problem may relate to the base addresses used by the Silverfrost linker and by the relevant Microsoft DLL. This being the case, you will not get the same problem if you were to test with a different C compiler. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|