- Timestamp:
- 08/21/11 17:09:09 (13 years ago)
- File:
-
- 1 edited
-
ps/trunk/source/lib/pointer_typedefs.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/lib/pointer_typedefs.h
r10025 r10053 13 13 // supported types: void, signed/unsigned 8/16/32/64 integers, float, double, XMM 14 14 15 // NB: `restrict' is not going into C++0x, so use __restrict to maintain compatibility 16 // with VC2010. 15 // which general type of pointer should be used in various situations? 16 // it would be convenient (especially for allocators) to allow easy 17 // pointer arithmetic. char* is one such option. However, that type of 18 // pointer (and also u8*) has a special dispensation for aliasing with 19 // _anything_ [C99 6.5(7) - we refer to that standard because __restrict 20 // compiler extensions are most likely to conform to its semantics], 21 // which might prevent optimizations. 22 // 23 // storing the address in uintptr_t (signed integers must never overflow) 24 // does allow easy arithmetic. unfortunately, the ASSUME_ALIGNED macro 25 // requires a pointer type. it is not clear whether casting to a pointer 26 // provides the same benefit. 27 // 28 // GCC and MSVC also provide a function attribute indicating a 29 // non-aliased pointer is being returned. however, this propagation 30 // does not seem to be reliable, especially because compilers may 31 // lose track of pointers [1]. it is therefore a waste of effort to 32 // annotate ALL pointers with cumbersome declarations, or pollute 33 // public interfaces with the following (little-known) typedefs. 34 // 35 // performance-critical code should instead introduce restricted 36 // pointers immediately before they are used to access memory. 37 // when combined with ASSUME_ALIGNED annotations, this would seem to 38 // provide all of the benefits of pointer analysis. it is therefore 39 // safe to use uintptr_t wherever convenient. however, callers usually 40 // expect a void* parameter or return value (e.g. in STL allocators). 41 // that seems a reasonable convention without any apparent downsides. 42 // 43 // in summary: 44 // - void* for public allocator interfaces; 45 // - uintptr_t for variables/arguments (even some public ones) 46 // which are frequently the subject of address manipulations; 47 // - restrict-qualified pointers via the following typedefs 48 // [plus ASSUME_ALIGNED, if applicable] shortly before 49 // accessing the underlying storage. 50 // 51 // 1: http://drdobbs.com/cpp/184403676?pgno=3 52 53 // NB: `restrict' is not going into C++0x, so use __restrict to 54 // maintain compatibility with VC2010. 17 55 18 56 typedef void* pVoid;
Note:
See TracChangeset
for help on using the changeset viewer.
