dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C#
Expertise: Beginner
Aug 15, 2005

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Structs with Care: Boxing

Consider an employee service, say in an SOA-based implementation, which exposes the following method:

Employee    getEmployeeInfo(int employeeId)
Looking at this signature, Employee can be defined as struct because it would be faster and lighter weight compared to defining Employee as a class:

struct Employee
{
int employeeId;
int department;
string name;
string designation;
string address;
....
}
In order to reduce network overhead, the Employee service should also provide the following overload:

Employee [] getEmployeeInfo(int[] employeeId)
Now, should Employee be a struct or a class (a value type or a referenece type)? Since the array is a reference type, boxing will kick in to convert the value type to a reference type at runtime and performance overhead will be incurred. This makes it sensible to make Employee a class rather than a struct.

Although this explanation cites an SOA-based implementation, it is applicable in any scenario involving boxing.

Navin Varma
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date