473,396 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Code generation

Hi

I'm trying optimize certain pieces of my code by generating and compiling
the source at runtime.

I need to make 2 methods for each class, a read and a write. I would like
to do this through generated code because than I don't need to use the
reflection all the time, nor do I need to box and unbox each item.

I would like to have a lazy approach here, I would like to generate and
compile the source as late as possible. I don't mind to compile the read
and write function at the same time.

Is it ok if I would make a seperate Assembly for each class? I would end up
with a couple of hundred tiny assemblies in my application then.

I have found examples on how to do this, but how can I "append" 2 methods to
an already existing in memory assembly? Without the need to recompile
everything. I would like to compile only those 2 methods or the class
containing these two methods.

kind regards

Alexander

Nov 17 '05 #1
2 1221
You actually don't need to save the assembly to disk. You can use the
TypeBuilder and AssemblyBuilder classes of the System.Reflection.Emit
namespace to build them in memory and use it directly without saving it to
disc.
--
Brian Delahunty
Ireland

http://briandela.com/blog
"Alexander Muylaert" wrote:
Hi

I'm trying optimize certain pieces of my code by generating and compiling
the source at runtime.

I need to make 2 methods for each class, a read and a write. I would like
to do this through generated code because than I don't need to use the
reflection all the time, nor do I need to box and unbox each item.

I would like to have a lazy approach here, I would like to generate and
compile the source as late as possible. I don't mind to compile the read
and write function at the same time.

Is it ok if I would make a seperate Assembly for each class? I would end up
with a couple of hundred tiny assemblies in my application then.

I have found examples on how to do this, but how can I "append" 2 methods to
an already existing in memory assembly? Without the need to recompile
everything. I would like to compile only those 2 methods or the class
containing these two methods.

kind regards

Alexander

Nov 17 '05 #2
Brian Delahunty <Br************@discussions.microsoft.com> writes:
You actually don't need to save the assembly to disk. You can use the
TypeBuilder and AssemblyBuilder classes of the System.Reflection.Emit
namespace to build them in memory and use it directly without saving it to
disc.


Unless there's an absolute need to create instance methods in separate
classes, it is more convenient to use the newly added
System.Reflection.Emit.DynamicMethod to create static methods. No
need for creating assemblies, classes, and so on.

That produces an object that can be cast to a delegate type and called
as a delegate without any boxing or unboxing.

Peter
--
Department of Natural Sciences http://www.dina.kvl.dk/~sestoft/
Royal Veterinary and Agricultural University * Tel +45 3528 2334
Thorvaldsensvej 40, DK-1871 Frederiksberg C, Denmark * Fax +45 3528 2350
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
8
by: Max M | last post by:
Yesterday there was an article on Slashdot: http://books.slashdot.org/article.pl?sid=03/09/04/1415210&mode=flat&tid=108&tid=126&tid=156 It is about automatic code generation. I got interrested...
0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
8
by: Wilk Teverbaugh | last post by:
I'm using get rows to build a table for a calendar. The specific view for this calendar is for an entire month. Each appointment slot is one half hour long. If I were to generate a page for the...
1
by: Gina | last post by:
I need to add the cell generation to a templated program. I am using graphics magician, but my problem is with the math. I cannot figure out my cell generations. I do know that I need two...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
9
by: Hayato Iriumi | last post by:
Hello, I hear some hypes about creating code to generate C# or VB .NET code, that is, code generation (sounds straight forward enough). I haven't really seen how it's done in real world. I'm...
4
by: Julia | last post by:
Hi, Is there any why I could use attribute or something else to instruct the compiler to inject a specific code for a property? for example i have the following property and i would like that...
1
by: George Meng | last post by:
I want to evaluate some code generation tool for my company. Want to get some idea from you. The bottom line is I want to get a tool to generate both store procedure as well as business object...
31
by: eliben | last post by:
Hello, In a Python program I'm writing I need to dynamically generate functions and store them in a dict. eval() can't work for me because a function definition is a statement and not an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.