Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: onytoo
  Where is onytoo?
 Padang
 Indonesia
 onytoo
 To: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 Tags
Subject: RE: declare warning
Thread ID: 310907 Message ID: 311038 # Views: 45 # Ratings: 0
Version: Visual FoxPro 9 Category: Projects and Design
Date: Tuesday, June 28, 2011 12:15:01 PM         
   


> > Hi all,
> >
> > this is an old story, but I meet it again while written and tunning web services.
> >
> > In short, the "declare dll" command is very slow. Declaring dlls inside the functions can dramatically slowdown the speed. On my PC it is about 3000x slower than declaring it once (in the main).
> >
> > Just see & try the example:
> > 
> > *
> > * speed test of "declare dll" command
> > *
> > #define MTIMES 1000
> > 
> > m.sec=seconds()
> > for m.i=1 to MTIMES
> > 	=test1()
> > endfor
> > m.sec=seconds()-m.sec
> > ? m.sec
> > 
> > declare integer GetLastError in kernel32 as w32_GetLastError
> > m.sec=seconds()
> > for m.i=1 to MTIMES
> > 	=test2()
> > endfor
> > m.sec=seconds()-m.sec
> > ? m.sec
> > 
> > 
> > function test1
> > 	declare integer GetLastError in kernel32 as w32_GetLastError
> > 	return w32_GetLastError()
> > 
> > function test2
> > 	return w32_GetLastError()
> > 
> > 

> >
> >
> > I wrote this message, because I see many exmaples of using winapi, declaring in-place.
> > Just, I think that declare-dlls MUST be executed only one time, at the beginning.
> > Hope that this can be useful info.
> >
> > Martin
>
> Martin,
> You are absolutely right about that, it is slow.
> However, OTOH, having all the DLLs declared from the start and kept in memory is not good either (not something I tested, just assuming it shouldn't be). My approach depends on how often I would use some API. Is that something that I would use just a few times in a routine? If so I prefer having it part of the function. Is that something that I need in a loop (ie: create thousands of GUIDs)? If so then I declare first and then call the function (the function may simply have a flag parameter to signal if it should run the 'declare inside function' version. ie:)
>
>
function SomeAPICaller(tlDeclared)
> if !m.tlDeclared
>   declare ...
> endif
> 

>
> Cetin Basoz
>
> .Net has got better.Think about moving - check my blog:
> My Blog
> Blog (mirror) - sounds to be down


Maybe I'm wrong Cetin, but if after we declares any api function from anywhere and even once, their will keep in memory until we use any command like CLEAR DLLS / CLEAR ALL or until app quit.

CMIIW


Regards,
Onytoo

ENTIRE THREAD

declare warning Posted by Martin Krivka @ 6/27/2011 7:37:00 AM
RE: declare warning Posted by Martina Jindrov√° @ 6/27/2011 7:58:16 AM
RE: declare warning Posted by Martin Krivka @ 6/27/2011 9:04:43 AM
RE: declare warning Posted by onytoo @ 6/27/2011 8:29:25 PM
RE: declare warning Posted by Ilya Rabyy @ 6/28/2011 6:57:26 PM
RE: declare warning Posted by onytoo @ 6/28/2011 9:27:55 PM
RE: declare warning Posted by Ilya Rabyy @ 6/29/2011 11:38:01 PM
RE: declare warning Posted by onytoo @ 6/30/2011 9:18:57 AM
RE: declare warning Posted by Martin Krivka @ 6/28/2011 9:29:38 PM
RE: declare warning Posted by onytoo @ 6/28/2011 9:41:42 PM
RE: declare warning Posted by Martin Krivka @ 6/28/2011 10:19:09 PM
RE: declare warning Posted by Ilya Rabyy @ 6/29/2011 11:42:56 PM
RE: declare warning Posted by Martin Krivka @ 6/30/2011 8:46:05 AM
RE: declare warning Posted by Ilya Rabyy @ 6/30/2011 4:34:36 PM
RE: declare warning Posted by Martin Krivka @ 6/30/2011 5:20:37 PM
RE: declare warning Posted by Ilya Rabyy @ 6/30/2011 6:21:06 PM
RE: declare warning Posted by onytoo @ 6/30/2011 10:14:51 PM
RE: declare warning Posted by Ilya Rabyy @ 6/30/2011 10:45:55 PM
RE: declare warning Posted by onytoo @ 7/1/2011 12:13:20 AM
RE: declare warning Posted by Samir H. @ 7/1/2011 5:53:19 AM
RE: declare warning Posted by onytoo @ 7/1/2011 10:59:04 AM
RE: declare warning Posted by Ilya Rabyy @ 7/1/2011 4:37:50 PM
RE: declare warning Posted by onytoo @ 7/1/2011 7:35:38 PM
RE: declare warning Posted by Mike Yearwood @ 7/1/2011 2:31:27 AM
RE: declare warning Posted by Cetin Basoz @ 6/28/2011 11:02:20 AM
RE: declare warning Posted by Martin Krivka @ 6/28/2011 12:09:38 PM
RE: declare warning Posted by onytoo @ 6/28/2011 12:15:01 PM
RE: declare warning Posted by Samir H. @ 6/28/2011 2:17:07 PM
RE: declare warning Posted by Martin Krivka @ 6/28/2011 3:41:05 PM
RE: declare warning Posted by Cetin Basoz @ 6/28/2011 4:15:06 PM
RE: declare warning Posted by Martin Krivka @ 6/28/2011 9:18:29 PM
RE: declare warning Posted by onytoo @ 6/30/2011 9:28:04 AM