C++ struct member, what type to keep calendar time on iPhone?

I need to keep datetime in a C++ structure for an iPhone app. The time will be saved and restored into sqlite db. What is the best data type and corresponding API for this? My candidates are:

  1. time_t and struct tm from <ctime> and <time.h>
  2. NSTimeInterval from <NSDate.h>
  3. TimeValue from the QuickTime API

My instinct is to go with the good ole' C/C++ types from <time.h>. Any drawbacks down the road? Any other time type I miss that is a darling of the iPhone SDK?

-------------Problems Reply------------

NSTimeInterval and its CoreFoundation counterpart CFAbsoluteTime are the best values to use, as they include sub-millisecond accuracy (they're double-precision floating-point values). time_t and struct tm are only really used in certain BSD APIs (and struct timeval or struct timespec are more common there). TimeValue is only used to represent values and intervals within a media file, and is usually based on a configurable time base.

It depends completely upon what you are using the times for.

  • What precision do you need?
  • How many will be stored? (On average / worst case)

Store as much precision as you need, but no more. (But also think about future needs). You don't save appointment times to the nearest nanosecond - it doesn't make sense. However if you are recording some type of data where very small intervals are important, then you might save it to the precision of the system clock (often 100 nanosecond chunks), or even a bit finer than that to allow for future versions with better clocks.

If you are only storing small numbers (say less than a few thousand) then storage size and access speed are probably unimportant. If you are storing many records, then the size of the records may become important.

Apart from the above considerations, it doesn't really matter; as long as it is clearly documented.

I'm not familiar with the sqlite db. Does it have any native date/time type? If so, that is probably simplest -- as long as it meets your requirements.

Category:c# Views:0 Time:2009-05-22

Related post

  • How to set a struct member of type string 2009-11-26

    I have a struct which contains a member called char *text. After I've created an object from the struct, then how do I set text to a string? --------------Solutions------------- If your struct is like struct phenom_struct { char * text; }; and you al

  • SWIG Python to C++: TypeError trying to set struct member of type map 2012-01-24

    SWIG seems to be generating incorrect bindings for converting a struct field of type map, resulting in a TypeError trying to set the map field to a python dictionary. Is there an error I am missing? an unsupported use-case? a bug in SWIG? First the o

  • Concurrent access to struct member 2010-08-22

    I'm using 32-bit microcontroller (STR91x). I'm concurrently accessing (from ISR and main loop) struct member of type enum. Access is limited to writing to that enum field in the ISR and checking in the main loop. Enum's underlying type is not larger

  • C++ Union, Struct, Member type 2010-06-18

    If I have a class: class Odp { int i; int b; union { long f; struct { WCHAR* pwszFoo; HRESULT hr; }; }; } Union means that, of all values listed, it can only take on one of those values at a time? How does that work in terms of accessing these variab

  • which size of struct member alignment in VC bring performance benefit? 2010-07-15

    does struct member alignment in VC bring performance benefit? if it is what is the best performance implication by using this and which size is best for current cpu architecture (x86_64, SSE2+, ..) --------------Solutions------------- Perf takes a no

  • C: sizeof single struct member 2010-08-24

    I am trying to declare a struct that is dependent upon another struct. I want to use sizeof to be safe/pedantic. typedef struct _parent { float calc ; char text[255] ; int used ; } parent_t ; Now I want to declare a struct child_t that has the same s

  • sizeof a struct member 2010-10-05

    This question already has an answer here: C: sizeof single struct member 5 answers How can I get the size of a member in a struct in C? struct A { char arr[64]; }; i need something like that: sizeof(A::arr) thanks --------------Solutions-------------

  • Extract a struct member from an array of structs 2010-10-28

    I have an array of structures that contain multiple variables: struct test_case { const int input1; //... const int output; }; test_case tc[] = { {0, /**/ 1}, // ... {99, /**/ 17} }; int tc_size = sizeof(tc) / sizeof(*tc); and I want to extract a vec

  • call Struct member in C 2011-05-11

    I have a question regarding C, would appreciate those who are willing to share their knowledge. While I was reading a code, I got stumbbled in a struct that its member is called in a way that I have never seen before. The code basically is below : Co

  • struct member alignment - is it possible to assume no padding 2011-06-05

    Imagine a struct made up of 32-bit, 16-bit, and 8-bit member values. Where the ordering of member values is such that each member is on it's natural boundary. struct Foo { uint32_t a; uint16_t b; uint8_t c; uint8_t d; uint32_t e; }; Member alignment

  • The null value cannot be assigned to a member with type Int32 but strings work 2011-12-23

    I have a class that maps to a table using LINQ but not ORM. It works with all the strings in the class and displays them in the view. However, if I add any Int32, Int16 or DateTime I get the error The null value cannot be assigned to a member with ty

  • P/Invoke of struct with pointer to a struct member 2011-12-26

    If I am translating the signature of a native function into C# which takes a pointer to a struct, I define it as ref with the translated struct as the type. What is the correct way if that pointer to a struct is not a function parameter but an other

  • default value for struct member in C 2012-12-05

    Is it possible to set default values for some struct member? I tried the following but, it'd cause syntax error: typedef struct { int flag = 3; } MyStruct; Errors: $ gcc -o testIt test.c test.c:7: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’

  • Why doesn't C++ have a pointer to member function type? 2009-01-20

    I could be totally wrong here, but as I understand it, C++ doesn't really have a native "pointer to member function" type. I know you can do tricks with Boost and mem_fun etc. But why did the designers of C++ decide not to have a 64-bit pointer conta

  • Does accessing a single struct member pull the entire struct into the Cache? 2009-12-21

    I've been reading Ulrich Drepper's, "What every programmer should know about memory" and in section 3.3.2 Measurements of Cache Effects ( halfway down the page ) it gives me the impression that accessing any member of a struct causes the whole struct

  • LINQ - Select Statement - The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type 2010-03-15

    I am trying to achieve the following... _4S.NJB_Request request = (from r in db.NJB_Requests where r.RequestId == referenceId select r).Take(1).SingleOrDefault(); Getting the following exception... Message: The null value cannot be assigned to a memb

  • Can C/C++ compiler report struct member offset 2010-05-25

    Possible Duplicate: Layout of compiled objects Hello, everyone. I'd like to ask, can compiler(e.g. Visual C++) generate a report(.txt) telling struct member offset for a struct/all structs? If so, it helps debugging quite a lot. For example, when you

  • C problem, left of '->' must point to class/struct/union/generic type? 2010-05-28

    Trying to understand why this doesn't work. I keep getting the following errors: left of '->nextNode' must point to class/struct/union/generic type (Also all the lines with a -> in the function new_math_struct) Header file #ifndef MSTRUCT_H #de

  • how to make struct member pointer in assembly? 2010-06-02

    I'm trying to create a macro which would make easier to point to a structs member. Currently I am pointing to a structs member in assembly file using the STRUCT_NAME + offset method. For example if I want to point structs third member, I would have t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.132 (s). 11 q(s)