Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:58:07+00:00 2026-05-26T14:58:07+00:00

Can any one help me. I have this ‘unmanaged’ .NET code, which works on

  • 0

Can any one help me. I have this ‘unmanaged’ .NET code, which works on PC Platform and OSX with MonoTouch Device Simulator. But when I run the code on my iPad 2 device, it throws an exception. I have tried to make the code as simple to show the problem.

var buffer = new byte[ 8 ]; // Space for 2 float32.
float value = 123f;                                     

fixed (byte* ptr = &buffer[1])
{
    var fp = (float*)ptr;
    *fp = value;
}   

On my device, it works when index in &buffer[] is 0, 4 – four bytes aligned as a float32, but fails on all other.

I’m interested to know, is it a bug in the MonoTouch unsafe implementation or is it me, that miss some information about .NET and unsafe code.

I have made a work-around, were I read/write in 4 byte buffer when handle floats, and then copies the data to the correct place in the array, but still it could be nice to know, if I miss understand something about .NET / iPad devices floating point handling or it is a bug. It is no problem with int64 types.

We are using unsafe array handling, because of tcp communication to PLC devices, were we uses arrays of uint8/uint16 and transfer blocks of data for gain higher throughput of data.

If anybody has time, here is a function for test, to try reproduce it:

BugTest(8); // Returns “S0,S1,S2,S3,S4,S5,S6,S7,” On my pc and mac with iPad simulator.
BugTest(8); // Returns “S0,F1,F2,F3,S4,F5,F6,F7,” On my iPad device.


unsafe string BugTest(int numberOfIndexesTest)
{
    var testResult = new StringBuilder();
    var buffer = new byte[ numberOfIndexesTest + sizeof(float)];    
    float value = 123f;                                     

    for(var index=0; index<numberOfIndexesTest;index++)
    {
        try
        {
            fixed (byte* ptr = &buffer[index])
            {
                var fp = (float*)ptr;
                *fp = value;

                testResult.AppendLine(string.Format("S{0},", index));
            }   
        }
        catch(Exception e)
        {
            testResult.AppendLine(string.Format("F{0},", index));
        }
    }

    return testResult.ToString ();
}

Thanks alot,

Best regards,
Casper Wollesen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:58:08+00:00Added an answer on May 26, 2026 at 2:58 pm

    This is not a MonoTouch issue since you would have the same issue in C, C++, ObjectiveC…

    The ARM processor, used in iOS devices, requires the float to be aligned on 4 bytes boundaries. The x86 architecture does not have this requirement – which is why it works on the simulator, OSX, Windows…

    UPDATE: ARM structured alignment FAQ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one help me with this syntax issue with C#? I have no
hi to all can any one help me with this problem i have brackets
I have a extension method. Can any one help me how to test this
i have a c problem can any one help me . i wrote a
Can any one help me please, I have two sections of my question. What
i have a string.i need to convert it to Voice. can any one help
I wonder if anyone can help - I have this error showing recently when
Can anyone help me getting started with this? We have a current keygen for
can anyone help? I have a simple html file which i am filling via
Can anyone help? I have an issue with calling a asp.net webservice from jquery..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.