From: Oscar F. <of...@wa...> - 2003-02-24 05:21:25
|
Adrien Mercier <ie...@ou...> writes: > Hi, > > I am trying to compile some source code picked up from the net, because > i will have to adapt it to fit my own needs. My goal is to obtain a dll > as small as possible. > > The problem is this program is using the nanosleep function, and this > function is definitly needed for the algorithm in itsef ( i cannot > afford to take sleep for example, because i need to sleep just for a > nanosecond). This is nonsense. Todays fastest PC's have a CPU cycle of about 0.3 ns. Even if that function is an instrinsic, whatever setup it needs to do for performing its task takes more than a nanosecond. For this kind of job you will need special CPU support (not provided by x86, AFAIK) or carefully code a good bunch of extremely complex machine code. OTOH, on a preemptive non real time OS like Windows, you can't guarantee *any* degree of accuracy while performing waits, except perhaps for kernel-level code. I guess that 'nanosleep' is just 'sleep' with a time interval specified as ns. The 1 second resolution of the *nix 'sleep' is too coarse and possibly the implementors of nanosleep just wanted to create something that will not become obsolete on the coming decades. > When I try to compile it using mingw, i got the "undefined > reference" to nanosleep, even though the time.h is in the include of > the file. I guess this function is not implemented yet. If it is a *nix function, it is normal that Cygwin implements it. Cygwin tries to emulate a POSIX environment on Windows. MinGW, OTOH, is "just" a development kit for developing *native* Windows applications. Don't hold your breath until somebody contributes it, much less until it becomes part of the standard MinGW distribution. > Thus i tried cygwin, and I succeded ( i'm not THAT bad ;) ) but the > problem is now that as i will have to distribute this program as a DLL, > i will have to distribute with it CYGWIN's dll, which is quite huge ( > 888Ko...) and that definitly doesn't suits my needs. > > Thus, here are my questions : > -Is it possible not to have to distribute the cygwin's dll along with > program builded with cygwin or programs using dll made with cygwin ? As Cygwin's source code is available, possibly you can build a static version of the library. I don't know for sure. Anyways, this is not the correct forum for asking about Cygwin. Try its own mailing lists. > -Is there any way to get the nanosleep function work with mingw ? For 1 nanosecond resolution? Naaa :-) > -Is there any other gcc compiler for windows out there that can meet > both these requirements ? The problem is not the compiler. It is the function. First of all, check that the function is supposed to do what you want to do. Sometimes function's names and parameter specifications are misleading about its real purpose. The 'Sleep' Win32 function, for instance, takes the time interval as milliseconds. Its accuracy is far from being into the millisecond range, though. For instance, this piece of code #include <windows.h> int main() { for(unsigned i = 0; i < 1000; ++i) Sleep(4); } needs 10.5 seconds to run on my system, when it should run on 4 seconds. I'm curious about a similar test with your 'nanosecond' function. > The source code i'm trying to compiled is supposed to be compatible > with "both linux and windows gcc". Lots of old source code packages says "windows gcc" when they mean Cygwin's gcc. -- Oscar |