Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Generics in NETMF


  • Please log in to reply
3 replies to this topic

#1 Dan Morphis

Dan Morphis

    Advanced Member

  • Members
  • PipPipPip
  • 188 posts

Posted 11 February 2011 - 07:12 PM

I realize this is the wrong forum for this question, but I'm not sure where to ask, so this will have to do :) Having become used to the power and simplicity that generics offer in the regular .NET Framework, is there any chance they will come to NETMF?

#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 11 February 2011 - 07:40 PM

Having become used to the power and simplicity that generics offer in the regular .NET Framework, is there any chance they will come to NETMF?

According to the information provided on the official site, "Generics would increase the footprint seriously". I guess it may be added in future, if the demand is strong enough, at least on platforms that would have sufficient resources.

#3 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 12 February 2011 - 05:40 AM

Having become used to the power and simplicity that generics offer in the regular .NET Framework, is there any chance they will come to NETMF?

I don't have any special insight into what Microsoft is doing or what Bill Gates wants to spend his money on, but I think it's extremely unlikely.

The reason is that (unlike templates in C++, where all the work is done by the compiler at compile time), generics in C# require a lot of support from the runtime. This means that the Micro Framework would have to be completely rewritten (and it would also need more RAM). I'm not saying it's impossible, but it would be a huge undertaking.

To give you an idea of just one of the many issues involved, below is a simple program which uses a type that the compiler has no chance of knowing, differs for every run of the program, and is not even determinable until runtime:

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace ConsoleApplication9 {
  public class Program {
    public static void Main() {
      Debug.Print(Func1<double>(new Random().Next(500)));
    }

    private static string Func1<T>(int depth) where T : new() {
      if(depth==0) {
        return Func2(new T());
      } else {
        return Func1<List<T>>(depth-1);
      }
    }

    private static string Func2<T>(T arg) {
      return arg.GetType().FullName;
    }
  }
}

Note: this is full-framework code, not Micro Framework code. And, by the way, the above program is literally impossible to write in C++ :)

#4 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 12 February 2011 - 08:21 AM

It might be safe to state that, it's rather unlikely ever to implemented on small devices like the Netduino. Sadly.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.