- Netduino Forums
- → Ravenheart's Content
Ravenheart's Content
There have been 18 items by Ravenheart (Search limited from 14-May 23)
#14019 Why so slow processing time?
Posted by Ravenheart on 07 June 2011 - 02:49 PM in General Discussion
#10989 netduino/MF performance
Posted by Ravenheart on 16 March 2011 - 03:31 PM in General Discussion
The .NET Micro Framework is an interpreter, once you get your assembly stripped out that gets sent to the Netduino and that is interpreted when it runs. At no point does your C# project get compiled to native code.Hi Daman.
I did not understand well what is your problem.
What I am tell you, is that the CLR is a very complex layer. Once you have written your C# code, the compiler creates an intermediate-language which is "portable". This is compiled again to native opcodes and sent to the Netduino.
The "overhead" of the CLR stands essentially in the memory management, which is garbage-collected automatically. This process gives you an huge simplicity to develop applications, a really safer way to play with objects, but it has a cost in terms of performance.
Just for have an idea of the timings, the only port read/write tight-loop is able to run at about 8.5KHz. That's is really "disappointing" for a 48MHz chip, but if you were just toggling an output, it's probably easier to write in assembler of C. Instead C#+Micro Framework has huge advantages when you want to embed very complex blocks: e.g. sockets, displays, threading, etc.
Hope it helps.
Cheers
Mario
EDIT: And I was slower to answer
#10305 Chris the star!
Posted by Ravenheart on 27 February 2011 - 11:42 AM in General Discussion
#8008 Graphical LCD
Posted by Ravenheart on 20 January 2011 - 05:59 PM in Netduino 2 (and Netduino 1)
#7485 Use of Static Keyword
Posted by Ravenheart on 12 January 2011 - 12:45 AM in General Discussion
#4357 Netduino at PDC 2010 (or watch online)...
Posted by Ravenheart on 29 October 2010 - 11:43 PM in General Discussion
#4353 Netduino at PDC 2010 (or watch online)...
Posted by Ravenheart on 29 October 2010 - 08:02 PM in General Discussion
#3353 MS ARM Compiler support
Posted by Ravenheart on 01 October 2010 - 01:14 PM in General Discussion
#2478 Live webcam and sound.
Posted by Ravenheart on 19 September 2010 - 03:09 PM in General Discussion
#2463 What is need to get started with Netduino?
Posted by Ravenheart on 19 September 2010 - 07:48 AM in General Discussion
#2432 Controlling a LED Intensity
Posted by Ravenheart on 18 September 2010 - 07:36 PM in General Discussion
#2425 Controlling a LED Intensity
Posted by Ravenheart on 18 September 2010 - 03:35 PM in General Discussion
#2400 Application always in running
Posted by Ravenheart on 17 September 2010 - 08:20 PM in General Discussion
#2082 BitConverter
Posted by Ravenheart on 10 September 2010 - 11:58 AM in Project Showcase
In order to use this open your project's Properties and tick the "Allow unsafe code" checkbox under the Build tab.
You are free to use the code in any type of project(commercial, open-source etc.), you can modify and distribute the code as you wish.
Note that using unsafe code is not documented, so even though it works fine under test conditions, we can't be sure just yet that it doesn't have side effects.
public static class BitConverter { public static unsafe long DoubleToInt64Bits(double value) { return *(((long*)&value)); } public static unsafe double Int64BitsToDouble(long value) { return *(((double*)&value)); } public static byte[] GetBytes(bool value) { return new byte[] { (value ? ((byte)1) : ((byte)0)) }; } public static byte[] GetBytes(char value) { return new byte[2] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF) }; } public static byte[] GetBytes(short value) { return new byte[2] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF) }; } public static byte[] GetBytes(ushort value) { return new byte[2] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF) }; } public static byte[] GetBytes(int value) { return new byte[4] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 24) & 0xFF) }; } public static byte[] GetBytes(uint value) { return new byte[4] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 24) & 0xFF) }; } public static byte[] GetBytes(long value) { return new byte[8] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 24) & 0xFF), (byte)((value >> 32) & 0xFF), (byte)((value >> 40) & 0xFF), (byte)((value >> 48) & 0xFF), (byte)((value >> 56) & 0xFF)}; } public static byte[] GetBytes(ulong value) { return new byte[8] { (byte)(value & 0xFF), (byte)((value >> 8) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 24) & 0xFF), (byte)((value >> 32) & 0xFF), (byte)((value >> 40) & 0xFF), (byte)((value >> 48) & 0xFF), (byte)((value >> 56) & 0xFF)}; } public static unsafe byte[] GetBytes(float value) { int val =*((int*)&value); return GetBytes(val); } public static unsafe byte[] GetBytes(double value) { long val = *((long*)&value); return GetBytes(val); } public static bool ToBoolean(byte[] value, int index = 0) { return value[index] != 0; } public static char ToChar(byte[] value, int index = 0) { return (char)(value[0 + index] << 0 | value[1 + index] << 8); } public static short ToInt16(byte[] value, int index = 0) { return (short)( value[0 + index] << 0 | value[1 + index] << 8); } public static int ToInt32(byte[] value, int index = 0) { return ( value[0 + index] << 0 | value[1 + index] << 8 | value[2 + index] << 16 | value[3 + index] << 24); } public static long ToInt64(byte[] value, int index = 0) { return ( value[0 + index] << 0 | value[1 + index] << 8 | value[2 + index] << 16 | value[3 + index] << 24 | value[4 + index] << 32 | value[5 + index] << 40 | value[6 + index] << 48 | value[7 + index] << 56); } public static ushort ToUInt16(byte[] value, int index = 0) { return (ushort)( value[0 + index] << 0 | value[1 + index] << 8); } public static uint ToUInt32(byte[] value, int index = 0) { return (uint)( value[0 + index] << 0 | value[1 + index] << 8 | value[2 + index] << 16 | value[3 + index] << 24); } public static ulong ToUInt64(byte[] value, int index = 0) { return (ulong)( value[0 + index] << 0 | value[1 + index] << 8 | value[2 + index] << 16 | value[3 + index] << 24 | value[4 + index] << 32 | value[5 + index] << 40 | value[6 + index] << 48 | value[7 + index] << 56); } public static unsafe float ToSingle(byte[] value, int index = 0) { int i = ToInt32(value); return *(((float*)&i)); } public static unsafe double ToDouble(byte[] value, int index = 0) { long l = ToInt64(value); return *(((double*)&l)); } public static string ToString(byte[] value, int index = 0) { return ToString(value, index, value.Length - index); } public static string ToString(byte[] value, int index, int length) { char[] c = new char[length * 3]; byte b; for (int y = 0, x = 0; y < length; ++y, ++x) { b = (byte)(value[index + y] >> 4); c[x] = (char)(b > 9 ? b + 0x37 : b + 0x30); b = (byte)(value[index + y] & 0xF); c[++x] = (char)(b > 9 ? b + 0x37 : b + 0x30); c[++x] = '-'; } return new string(c, 0, c.Length - 1); } }
#2076 SchmartBoard
Posted by Ravenheart on 10 September 2010 - 01:36 AM in General Discussion
#1968 FEZ Panda
Posted by Ravenheart on 08 September 2010 - 10:30 PM in General Discussion
#1959 FEZ Panda
Posted by Ravenheart on 08 September 2010 - 07:55 PM in General Discussion
#1945 Arduino or Netduino
Posted by Ravenheart on 08 September 2010 - 05:10 PM in General Discussion
- Netduino Forums
- → Ravenheart's Content
- Privacy Policy