Jump to content
  • Advertisement


  • 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 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 How should I pass the callback signature to std::function?? I am compiling on gcc 4.6
  2. littlekid

    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. littlekid

    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: 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] 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(#)) //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; }; 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. 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?? 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 }
  8. 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. littlekid

    how and when shoud I use volatile keyword?

    would this work?? [source] class Thread { public: void PostQuitSignal() { quit_.store(true, 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. littlekid

    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. littlekid

    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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!