Jump to content

  • Log In with Google      Sign In   
  • Create Account

floatingwoods

Member Since 09 Jun 2008
Offline Last Active Today, 12:33 AM

Topics I've Started

Data alignment on ARM processors

Yesterday, 10:20 AM

Hello,

 

I recently faced a problem with some C code, on ARM processors, where data alignment is of importance. I typically have following 2 scenarios:

float value=doLittleBigEndianConversion(((int*)(ucharPtr+offset))[0]);

and

((int*)(ucharPtr+offset))[0]=someIntValue;

Depending on the offset, I get some crashes. So the solution to scenario 1 is (for instance):

float value;
memcpy (&value,ucharPtr+offset,sizeof(float));
value=doLittleBigEndianConversion(value);

Which solves the alignment problem. My question is now: How can I fix the scenario2 code, so that it also works on ARM processors?

 

Thanks for any insight!


std::sort corrupts my memory

20 April 2016 - 12:58 AM

Hello,

 

I have a strange behaviour I can't explain. I have this structure:

 

struct SMyStruct {
    int x;
    int y;
    bool operator< (const SMyStruct& m) const {return true;}
};

with following code:


std::vector<std::pair<float,SMyStruct > > items;
for (size_t i=0;i<8;i++)
{
    SMyStruct a;
    a.x=i;
    for (size_t j=0;j<8;j++)
    {
        a.y=j;
        items.push_back(std::make_pair(0.0,a));
    }
}

std::sort(items.begin(),items.end());

for (size_t i=0;i<items.size();i++)
{
    int x=items[i].second.x;
    int y=items[i].second.y;
    printf("i: %i --> %i, %i\n",i,x,y);
}

The above code was simplified, but the idea is to basically sort items according to a float value (in above code that float value is always 0.0). Above will corrupt my memory and later crash. Also, the output is mostly correct, but sometimes I get very large, non-logical values for x and y, after the sort. I can't figure out where I made a mistake. But I can fix that strange behaviour by having the comparison operation of the struct always return false instead of true (since I only care about sorting according to the float value of the pair I can return true or false).

 

Can anyone see where there is a bug in above code?

 

 


Data organization with graphics front-end

03 November 2015 - 12:11 PM

Hello,

 

I am wondering what the common approaches to following problem are:

 

Imagine an application that does some sort of computation or simulation on a complex data structure (e.g. several hundreds of different objects types). That application can run in headless mode (i.e. without GUI or graphics fron-end). Imagine also that this application just needs a single thread. In case of a game, this thread would handle the game logic and read/write the data.

 

Above is not too complicated, but what happens when we want the user to be able to constantly visualize the data structure (e.g. display the game evolution in 2D/3D for instance). Imagine that for this part, a second thread is used.

 

Now, how can we optimized everything for fastest and safest operation? I mean, the graphics thread and the computation thread cannot access the data at the same time, unless we read it only, which is not the case (or rarely).

 

So I see several options:

 

1. The two threads access the same data alternately, but never at the same time. This is not very elegant, since the two threads would have to wait for each other.

 

2. The computation thread duplicates the complex data on a regular basis, and the graphics thread only accesses the duplicate portion of the data. My worries here is that the duplication process could take time (even if in the end it is just a complex memory copy operation).

 

3. The computation thread simply sends messages to the graphics thread when it modified something: we would have a kind of complex synchronization process that can easily break down. My worries here are: the synchronization can break if not very carefully implemented and the implementation is quite complex.

 

So my question is: what would be the best solution generally speaking? Or is there another solution to my problem?


Switching from float to double (and vice-versa) at compile time

16 June 2015 - 04:33 AM

Hello,

 

I have an application that mainly uses floats. I now want to be able to switch to double at compile time, with something like:

#ifdef DOUBLE
typedef float real;
#else
typedef double real;
#endif

Now I wonder how to handle following code (for example):

Initial:

float a=1.0f;
float b=2.0f;
float c=a*b*3.0f;

This would be rewritten to:

real a=1.0;
real v=2.0;
real c=a*b*3.0;

Notice the missing 'f'. What kind of implication would this have for when DOUBLE is not defined? It would be equivalent to:

float a=1.0;
float b=2.0;
float c=a*b*3.0;

The example is probably not appropriate, but in some older legacy code, this could lead to a different result, right?

 

How is the 'f' handled in case I want to have the compile-time float/double possibility? Just truncate all 'f'? Is there an elegant/correct way of doing this?

 

Thanks


How to check application version with HTTP GET?

14 March 2015 - 05:13 PM

Hello,

 

what is the simplest method to check if there is a new program version available?

I have my application, a server, and also a website. The application is c++.

How to send an http GET command, and how to serve it?

 

My idea was to simply have a text file on my website that contains a string (e.g. "version1.2.1"), and to retrieve it with GET. How to go about that, without having to add numerous includes and libraries to my application?

 

Thanks

 


PARTNERS