Git Product home page Git Product logo

dotnetex's Introduction

Build status dotnetex project

Gets size of .Net Framework objects, can change type of object to incompatible and can alloc .Net objects at unmanaged memory area Also contains examples to resolve .Net objects in virtual memory and fork() method.

   var size = GCex.SizeOf<Object>();    // prints 12 on 32-bit .Net Framework;
   var size = GCEx.SizeOf(someObject);  // prints size for already existing object;

SizeOf allows to compute size of any .Net type, including reference types, strings, arrays and so on.

  var from = new object();
  
  callSomeMethodOrJustCodeBlock();
  
  GCEx.EnumerateSOH(from).Select(obj => GCEx.SizeOf(obj)).Sum()

will compute sum of objects, which are allocated by callSomeMethodOrJustCodeBlock();

  static void MakeFork()
  {
      var sameLocalVariable = 123;
      var stopwatch = Stopwatch.StartNew();

      // Splitting current thread flow to two threads
      var forked = Fork.CloneThread();

      lock (Sync)
      {
          Console.WriteLine("in {0} thread: {1}, local value: {2}, time to enter = {3} ms",
              forked ? "forked" : "parent",
              Thread.CurrentThread.ManagedThreadId,
              sameLocalVariable, 
              stopwatch.ElapsedMilliseconds);
      }

      // Here forked thread's life will be stopped
      joined.Signal();
  }

Will make new thread, which will start its flow on Fork.CLone() call and will stop on caller's method exit.

  var heap = new UnmanagedHeap<Foo>(100);
  var obj = heap.Allocate();
  
  obj.CallMethod();
  
  heap.Free(obj);

Will create objects pool in unmanaged memory. Object will have type 'Foo' and pool's size will be 100. Performance tests for this pool:

Ctor call via reflection (on already allocated memory): 49575
Ctor call via method body ptr redirection: 1147
pure allocation in managed memory: 6162
Refl ctor call / ctor Redirection 43,22145 (higher is slower)   <--- 43 times faster than constructorInfo.Invoke()
ctor Redirection / newobj:        0,1861409 (higher is slower)  <--- 5 times faster than new T(int ..)
Refl ctor call / newobj:          8,045278 (higher is slower)   <--- using reflection is just 8 times faster than new T(int ...);

Bugs

Please feel free to add new bugs to our issue tracker (github's tracker)

dotnetex's People

Contributors

andreyakinshin avatar hmemcpy avatar mumusan avatar sidristij avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.