• Content count

  • Joined

  • Last visited

Community Reputation

229 Neutral

About littlekid

  • Rank
    Advanced Member
  1. Hihi, I was wondering how do I use decltype to get the signature to pass in std::function? suppose I have [code] typedef void (*MyFuncCallback)(); std::function<MyFuncCallback> callback_object; //doesn't work --- error: variable 'std::function<void (*)()> callback_object' has initializer but incomplete type std::function<decltype(MyFuncCallback)> callback_object; //doesn't work either [/code] How should I pass the callback signature to std::function?? I am compiling on gcc 4.6
  2. How to set Cache Line Alignment Properly

    I am already using boost.Thread and interlocked/atomic variables. But I think that both Boost.Thread and Interlocked variables can't really solve the problem of false sharing?
  3. How to set Cache Line Alignment Properly

    Thanks for the detailed reply I guess it is true that my example did not reflect a problem of cache trashing (or maybe i use the wrong word ). I do use interlocked variables, but have replaced them with std::atomic. The exact problem of my problem is actually where I have an array of data that can be accessed by multiple threads. For simplicity say something like: [code] struct Data {}; Data values[thread_count]; //in Thread One //do something like read/write to values[thread_id] //in Thread Two //do something like read/write to values[thread_id] [/code] but as each element of data might lie on the same cache line. I think this might causes potential false sharing? regards
  4. Hi, suppose I wish to align my data to a cache line to prevent cache trashing when accessing via multiple threads how should I do it easily? What is the difference between padding it manually or using those compiler keywords like __declspec(align(#)) or __attribute__(align(#)) [code] //E.g 1 struct Data { int a; char padding_0[CACHE_LINE_SIZE - sizeof(int)]; double b; char padding_1[CACHE_LINE_SIZE - sizeof(double)]; }; //E.g 2 __declspec(align(CACHE_LINE_SIZE)) struct Data { __declspec(align(CACHE_LINE_SIZE)) int a; __declspec(align(CACHE_LINE_SIZE)) double b; }; [/code] Is there any difference between the above 2 e.g? I know of ways to get the CACHE_LINE_SIZE programmatically e.g via GetLogicalProcessorInformation. But is there anyway to know it at compile time? It seems pointless to get the CACHE_LINE_SIZE programmatically as I can't change the padding size when the program is running. regards
  5. Hi I am trying to create a "pen tool" like simulation with opengl. I am rendering each point as a circle with a certain radius. It look decent when the user is drawing with a slow speed. However when the user move the mouse really fast, there would be gaps in between each drawn circle. Is there way to avoid this problem?? Off the top my head, I would think of joining up adjacent points with a line. However I was wondering if this would lead to blocky lines?? regards
  6. Hi I have some code in C++ that currently runs in windows 7 under MSVC2010. I would like to port my code and was wondering if there is any recommended graphics/shader library which supports a cross platform for iphone/win/mac. The most major concern that I would need is the support of GLSL I have looked at the cocos2D app, however it lacks shader support which is a key functionality of my program. Is there any suggested recommended libraries to look into?? regards
  7. How to get the exponent of a power of 2 value?

    Is it better to use the builtin functions as specified by Hodgman or would it be better to just use the log hacks offered by Sicrane? I was just wondering if does using any have a slight benefit over the other?? [code] For Hodgman solution this is what i did: size_t GetPowerTwoExponent(size_t value) { #if defined(MSVC_COMPILER) size_t index = 0; _BitScanForward(&index, value); return index; #elif defined(GCC_COMPILER) || defined(CLANG_COMPILER) return __builtin_ctz(value); #endif } [/code]
  8. How to get the exponent of a power of 2 value?

    [quote name='Dr1fter' timestamp='1305467263' post='4811071'] Are you using java? if so i know it has a getExponenent method in its math library. Example System.out.println(Math.getExponent(2)); would return 1 if your using another language i'm sure they should have similar methods available. [/quote] ah sorry, i didn't mentioned, I am using C++. I am not sure what functions in C++ can i use, other than maybe log?? regards
  9. Hi, suppose my value is always in power of 2 e.g 512, 1024, 32, 64. Is there any quick way of getting the exponent of it? for e.g 256 would yield an exponent of 8. Hence given the value 256, what quick fast way can I get the exponent value 8? I was thinking of looping the bits and then finding which bit position is set. Is that the best way to go about doing it? regards
  10. how and when shoud I use volatile keyword?

    would this work?? [source] class Thread { public: void PostQuitSignal() {, std::memory_order_relaxed); }; void ThreadLoop() { while(!quit.load(std::memory_order_acquire)) //this make sure no instruction is reorder?? { //do something } }; private: std::atomic<bool> quit_; }; [/source] I always thought that if the variable is within the bus width, i.e 32bit on at x86 machine, it would be atomic by nature? regards
  11. how and when shoud I use volatile keyword?

    hi, @ frob, I don't understand how to use boost.conditional_variable to replace the quit variable. As in this case, the quit_ variable is use as a flag by the thread to determine if it need to terminate, if not it continue processing its stuff. However wouldn't boost.conditional_variable cause the said thread to sleep or block when the condition is not met? regards
  12. how and when shoud I use volatile keyword?

    hi, @frob, what libraries do you suggest I use?? I am currently using most stuff from boost threads. lastly i am using gcc4.6 so I have access to std::atomic, but i did not use it as I thought writing and reading a bool is guarantee to be atomic? regards
  13. suppose i have this code [source] class Thread { public: void PostQuitSignal() { quit_ = true; } Desc GetDesc() { return desc_; } private: void ThreadLoop() { while (!quit_) { //do other main thread logic like read message queues etc } } bool quit_; //does this need to be volatile?? Desc desc_; //this struct is magically initialize with all values at constructor and never changes anymore, does this need to be volatile too?? }; [/source] suppose in a mulithread app, the above class when started will run ThreadLoop function. Does the variable "quit_" and "desc_" need to be volatile?? regards
  14. Hi suppose I create 1 - 4 windows each with their own opengl context that is shared. Is it better to have each context on a different thread?? Meaning, for e.g 4 opengl context would span over 4 thread. Or would it be more efficient to just place all contexts in a single thread and draw them. for other resources such as vbo and textures, I am sharing among the context, hence I am not duplicating vbo or textures 4 times. regards
  15. hi, I was wondering if it is possible to store indices and vertices on the same Buffer Object? For example I create a buffer object of size 1mb, and I write vertex data to say the first 512kb and write index data to the next 512kb? Is it possible to do such thing, or would it be not advisable to do it? I was thinking since I already have a buffer pool for vertex data, I might as well use it for indices too and even uniform data too. regards