Int32 or Int16?

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 11-Feb-2009 19:25:02   

Hi,

it looks like there are quite a few discussions on the internet regarding what data types to use in regards to Int32 or Int16..

According to the below reference, the runtime optimizes performance of Int32 and recommends them for counters and other frequently accessed operations.

From the book: MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation

Chapter 1: "Framework Fundamentals" Lesson 1: "Using Value Types"

Best Practices: Optimizing performance with built-in types

The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables.

For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.

Also, Table 1-1 in the same section lists recommended uses for each type. Relevant to this discussion:

* Int16 - Interoperation and other specialized uses
* Int32 - Whole numbers and counters
* Int64 - Large whole numbers

http://stackoverflow.com/questions/129023/-net-integer-vs-int16

This might be true but on the database level it's a different thing as it would take more space to have a million times an int rather than a smallint.

But if we do it on the database LLBLGen passes it right along to the code and we have Int16 in our entities....

Just wanted to see what your opinion on it is?

Thanks patrick

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 12-Feb-2009 10:28:26   

If you want to have Int16 in the database and Int32 in code, you may use a TypeConverter.

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 18-Feb-2009 05:23:30   

Walaa wrote:

If you want to have Int16 in the database and Int32 in code, you may use a TypeConverter.

How would I do that to all smallint in my project please?

Apart from that I would also be interested what others think about the topic in general.

Thanks, Patrick

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 18-Feb-2009 10:35:06   

How would I do that to all smallint in my project please?

In the Designer there is a plugin shipped called "Assign Type Converter", which you can run to all entities or a selected number of entities to automatically assign a specific type converter to all fields of a specific type.