AbsoluteToNanoseconds vs AbsoluteToDuration

Apple has extremely comprehensive documentation, but I can't find documentation for the AbsoluteToNanoseconds function? I had to find the difference between AbsoluteToNanoseconds and AbsoluteToDuration.

Note

Am I starting to think that Apple Docs only supports Objective-C features? Is that the case?

I found the following using Apple-double-click:

32-bit millisecond timer for drivers 64-bit AbsoluteTime clock

+3
source share
2 answers

I'm not sure why it is not documented anywhere, but here is an example of how it is used, if that helps

static float HowLong(
    AbsoluteTime endTime,
    AbsoluteTime bgnTime
    )
{
    AbsoluteTime absTime;
    Nanoseconds  nanosec;

    absTime = SubAbsoluteFromAbsolute(endTime, bgnTime);
    nanosec = AbsoluteToNanoseconds(absTime);
    return (float) UnsignedWideToUInt64( nanosec ) / 1000.0;
}

UPDATE:

" , , - , AbsoluteToDuration"

. AbsoluteToNanoseconds() Nanoseconds, UnsignedWide.

struct UnsignedWide {
  UInt32              hi;
  UInt32              lo;
};

, AbsoluteToDuration() Duration, SInt32 signed long:

typedef SInt32 Duration;

Durations , , . Nanoseconds, , , , .

+3

https://developer.apple.com/library/prerelease/mac/releasenotes/General/APIDiffsMacOSX10_9/Kernel.html,

SubAbsoluteFromAbsolute(), * * , Mavericks. .

, , , Mavericks Mountain Lion ( ), mach_absolute_time() , ( ) . , , clock_gettime Mac OS X , , . , , , , mach_timebase_info(), 1.

, , ( , Mac, ):

#include <CoreServices/CoreServices.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <time.h>
#include <iostream>

using namespace std;

int main()
{
   uint64_t now, then;
   uint64_t abs, nano;
   mach_timebase_info_data_t timebase_info = {0,0};

   then = mach_absolute_time();
   sleep(1);
   now = mach_absolute_time();
   abs = now - then;

   mach_timebase_info(&timebase_info);

   cout << "numerator " << timebase_info.numer << " denominator "
        << timebase_info.denom << endl;

   if ((timebase_info.numer != 1) || (timebase_info.denom != 1))
   {
      nano = (abs * timebase_info.numer) / timebase_info.denom;
      cout << "Have a real conversion value" << endl;
   }
   else
   {
      nano = abs;
      cout << "Both numerator and denominator are 1" << endl;
   }
   cout << "milliseconds = " << nano/1000000LL << endl;
}
+2

Source: https://habr.com/ru/post/1730318/


All Articles