Understanding and Troubleshooting Unmanaged Memory Usage in .NET



Writing in C# every day, we forget that we are in a privileged world. Underneath the abstraction of the virtual machine lies a batch of C++ code that is handling memory in the old fashioned way. Blocks of memory are allocated by asking a heap manager for a chunk of memory - you get a pointer to it and you can do exactly what you want with that memory. There's no associated type controlling your access to the memory and you're free to do what you like with it. Unfortunately that also means that you can write outside its bounds, or over any header that the heap manager has associated with the block. You can free the block and continue to use it too. All of these problems can lead to spectacular crashes.

Over time, patterns have been developed to handle some of these issues. C++ programs for example often encapsulate memory allocation using the RAII pattern, where blocks of memory are allocated for a particular lexical scope within the program. When the scope is exited, the destructor on a stack allocated object can ensure that the memory is released, and the object's API can ensure that the programmer does not get unrestrained access to the raw memory itself.

How unmanaged memory works, and when you use it
There are two ways to allocate unmanaged memory from .NET - by using the VirtualAlloc and VirtualFree functions, or by using AllocateHeap.
VirtualAlloc/VirtualFree lets you reserve a region of (4K) pages. You can choose between reserving chunks of the virtual address space, and allocating actual physical memory. The AllocateHeap API provides a heap manager that deals with small blocks of memory. This takes care of grabbing chunks from the operating system and handles memory management to avoid problems like fragmentation.
The C Runtime Library then has malloc and free functions that operate at a higher level, allowing it to do additional bookkeeping and debugging while keeping things portable.
Together, these tools let you manipulate unmanaged memory from within your managed application. There are essentially four different uses for that:
Heaps for the garbage collector, on which the managed objects live.
Data structures that the managed runtime uses to run the managed code. This includes space taken up by JITted code as well as other metadata.
Resources associated with managed objects, particularly those required for interoperability with the operating system, such as bitmaps.
Memory used by unmanaged components which are used by your managed code, e.g. third-party COM components.
Processes operate entirely within their virtual memory space, and do not usually control where the regions of memory they are using reside. The operating system manages which regions of virtual memory are held in physical memory (comprising the process working set) and which exist only on the hard drive. Additionally, pages in virtual memory may either be private, meaning they are accessible only to a particular process, or be shareable between multiple processes. Assemblies, DLLs, and mapped files can be shared, but the .NET heaps, JITted code, and most other run-time data is private.
How much is being used by what?
By default, Windows Task Manager shows the size of the private working set of a process, which consists of those memory pages which are both private and reside in physical memory. Pages may be moved in and out of the working set dynamically by the operating system, depending on how they are accessed and the amount of physical memory available.
ANTS Memory Profiler shows a breakdown of the total number of private bytes in virtual memory in a pie chart on the summary screen, regardless of whether they are in physical memory or not. The "unmanaged" section of the pie chart therefore includes JITted code, CLR metadata, and other unmanaged resources and memory allocations which are not shareable.
The CLR itself must allocate unmanaged memory to run your application. Some of this is for the garbage collector heaps that the objects are created on, which are displayed on the pie chart in ANTS Memory Profiler. The objects that you see in the class and instance lists all reside within these heaps. The CLR also requires unmanaged memory to store JITted code and perform internal bookkeeping. As a result, in applications which do not make significant use of unmanaged components, the CLR is usually responsible for...

Email Marketing is now free

Really it's free if you have a contact list less than 2000 then it is free .That's a great news.
For registration no credit card required.This is really an awesome.
Then why wait join with Lab5Connect now
Lab5 Connect makes email marketing a simple way to reach your audience. Our in-house
tool ensures delivery to your user’s inbox. Simply upload your mailing list,
create your email using one
of our attractive templates and hit the send button.
You don’t need to be a technical wizard to set up or perform an email blast. Once created
and sent,you can then monitor your campaign and view your audience statistics – from
open rates to click through to bounce backs, all in a user-friendly report
This video will gives more information .
.

Email Marketing for your business

Email marketing is directly marketing a commercial message to a group of people using email.
In its broadest sense, every email sent to a potential or current customer could be considered email marketing.
It usually involves using email to send ads, request business, or solicit sales or donations, and is meant to build loyalty, trust, or brand awareness. Email marketing can be done to either sold lists or current customer database.
Broadly, the term is usually used to refer to:
There are several examples of email marketing campaigns, starting with a welcome email that thanks that new contact for opting in to your subscription. Welcome letters can not only give valuable information about your company, they can also request key information about your new client, helping you put the person in the correct categories for future marketing efforts. Additional email campaigns include sending out announcements on products or services, a newsletter regarding your company and/or products, coupons for future purchasing and much more. Every email you send out should have company information on the bottom, giving potential clients a chance to learn more about your company as well as ‘opt-in’ to get future emails. Incentive programs that give members a ‘promo code’ to collect discounts on purchases also allow you to monitor the effectiveness of your campaign as well as what your contacts are interested in.

Email marketing has several key advantages over traditional mail marketing, including the following:

  • An exact return on investment can be tracked and has proven to be high when done properly. 
  • Email marketing is often reported as second only to search marketing as the most effective online marketing tactic.
  • Advertisers can reach substantial numbers of email subscribers who have opted in to receive email communications on subjects of interest to them.
  • Over half of all Internet users check or send email on a typical day.
  • Email allows marketers to reach out to consumers with personalized, relevant, dynamic messages.
The disadvantages of email marketing surround the rejection/spam rate of the emails by the consumers’ email program, negatively
Then Why to choose ?
Cost – Email marketing is CHEAP, there are no two ways about it. Whether you do it yourself, or through an email marketing agency, marketing to hundreds of consumers via email is going to cost you tiddlywinks compared to other channels of advertising.
Success - Emails can be targeting specifically to the ideal consumer. With this concept in mind, along with email cost-effectiveness, it’s no wonder that email marketing’s ROI often blows other direct marketing strategies out of the water – The trick is that you have to get it right!
Measureability and Flexibility – With the analytics available today it’s easy to track responses to your emails exactly, in order to work out what parts of your campaign are working and what parts aren’t. With this knowledge, you can then react instantly to modify your campaign strategy if need be.

How?
Creative – This refers to the overall design of the email (layout/images/colour). Specifically, it is a good idea to ask each customer whether they would like the emails in text or HTML as there is often a great preference for one over the other.

Relevance – Targeting, targeting, and more targeting. Make your emails relevent and personalised to each recipient if you want that response rate to rise.
Incentive - Recipients look at emails and think “WIIFM?”, i.e. “What’s in it for me??”. There’s no such thing as a free lunch right? Well… Offer the recipient a “free lunch” for participating and they will be more likely to respond.

Timing – Don’t send out an email that recipients will receive overnight, let it pop up in their inbox during their working day. This also expands to selecting certain days, months and even years. Remember – You can test and measure what timing works best for which email.

Integration – Companies can not just rely on one method of marketing, nor can they rely on several methods of differentiated marketing. Instead, best marketing practices utilise integrated marketing communication (IMC) where all aspects of their promotion work together to create a whole. Email marketing must be including here, therefore your emails must carry the same image and message as your entire operations. Even the timing of the campaign must work in with other aspects of your marketing mix.

Copy – When considering the copywriting for your email you must consider all aspects of the language, from subject line through to your mail signature. With emails, not all links should be saved for the last sentence, pop them in early to grab that impulsive customer!

Attributes – Here Dave talks about the email header, with attributes including the subject line, from address, to address, date/time of receipt and format. Once again, testing your campaigns can rule out the attributes that customers consider spam and highlighting the attributes that will work best for your business.
Landing Page – Want those emails to turn into sales conversions? Don’t just hyperlink your customers to your home page; show them exactly where you want them to go and make it quick and easy to complete any forms!

ASP.NET MVC Web-Tier


ASP.NET is a part of Microsoft® .NET® platform and is used to create web applications. It provides the environment and all the necessary support classes to run applications that can render themselves on down-level or up-level browsers, maintain state between sessions (even within a web farm), and more. ASP.NET does not dictate how an application should be built.
Using the UML model (PIM) as input, this Technology Accelerator will create a web application framework that uses ASP.NET. The scope of the Technology Accelerator is the presentation tier of a web application. The business and data tiers are outside the scope and are assumed to be created separately.
To use industry practices and diminish development effort as well as maintain separation of concerns, we have used the Model-View-Controller (MVC) architectural pattern within the web presentation tier.
The MVC web presentation tier will delegate to the business tier through two facades. These facades encapsulate the entire business tier through the view exposed by the business entities present in the PIM. These business entities do not represent the actual business tier but rather the view of the business tier as needed by the presentation tier to accomplish actions invoked by the user and return meaningful information. As long as the two facades cooperate using the data and actions exposed in the business entities, connection to any business tier is possible
.
     Web Client Interaction with a Web Page

C Viva Questions.........................

Viva Questions For C lab Examination...

1. C is ----------------type of language ?

Ans-Procedural.

2.Which are primitive datatypes in C?

Ans-int,Float,Char,Double,void ;

3.Memory size 0f int datatype?

Ans-2 bytes

4.Memory size of Character Datatype?
 

Ans-one bytes

5.Memory size of Float Datatype?

Ans-4 Bytes

6.What will be output of following code?

while(1)
{
 printf("A");
}

Ans- Character A will be pritented on Screen until Heap memory is full. After that program terminates..

7.Difference b/w while and do...While?

Ans- While is Entry control loop.
      Do While is Exit control Loop.


8.Which are user defined data types in C ?

Structure , Enumeration

9. What will following Statement indicates?

 const int Key=10;

Ans- key is declared as Constant throughout the program key will have value 10

10.Difference b/w function declaration and function defenition?
 

       Ans- Declaration means declaring a function.
       eg- int sum(int,int);
        It tell the compiler that we will use this function.
       Defention means we are telling what the function will do..
       eg- int sum(int a,int b)
       {
         int sum;
         sum=a+b;
          return(sum);
     }


11.Syntax for function defenition?

 returntype function name( datatype argument1,datatype argument1,.........argument n)
{
  //statements
 return( return value);
}



Related Posts:--
Data Structures Viva Questions

 

How can you Safely Use Pen can drives?

How can you Safely Use Pen can drives?

 Problem occur while using pen drives

Spreading of virus through pen drive is quite often.  When u copy some data’s from other computer then chance of spreading virus is quite often.

AM I  safe with an anti virus and update regularly?

Not completely because all anti virus are made for some virus. Every anti virus is not capable of removing all viruses.

Solution

First of all you need to install a new OS .Say for example UBUNTU .Note that second OS will not be any version of primary OS.
It is better using any Linux OS because. It is open source and virus free.  Now when ever u wants to plug a pen drive Log onto Secondary OS and open pen drive. Then you can see all files in the pen drive including virus files. Normally in windows these virus files are hidden and thus we cannot see. Delete that files and search whether it is present in other folders. Remove if it found there.

How will you identify a virus?

Case 1: - It is not a difficult task. Consider u had copied only mp3 songs from other computer. Then any other files see other than mp3 type are viruses.
Note: - There may be 1 hidden files “thum.db” which is not virus .its thumb nail image of that folder.

Case 2:- if u copied images or video files case 1 is true here.

Case 3: - If copied software .Now thing will be more difficult. Here u needs to know virus files name in advance. If found delete it .If u don’t know virus name then use another method. Normally virus are presented outside all the folders . and that would be found in all folders too. Try to find all and delete it

Now Enjoy safely using pen drive and save Pc from Viruses


Data Structure Viva Questions

Q1.What is a Register?

Ans- A register is a small amount of memory within the CPU that is used to temporarily store instructions and data.

Q2.An _________ data type is a keyword of a programming language that specifies the amount of memory needed to store data and the kind of data that will be stored in that memory location?

Ans-abstract

Q3.What are the different Abstract Data Type Groups?

A) Integer, Floating-Type, Character & Boolean are the four different data type groups
Explanation: You determine the amount of memory to reserve by determining the appropriate abstract data type group to use and then deciding which abstract data type within the group is right for the data. The different abstract data type groups are Integer, Floating-Type, Character & Boolean

Q4.Which of the following abstract data types are NOT used by Integer Abstract Data type group?

A) Short
B) Int
C) float
D) long
Explanation: The integer abstract data type group consists of four abstract data types used to reserve memory to store whole numbers: byte, short, int , and long

Q5.What pointer type is used to implement the heterogeneous linked list in C?

The answer is the void pointer. The heterogeneous linked list contains different data types in it's nodes and we need a link, pointer, to connect them. Since we can't use ordinary pointers for this, we use the void pointer. Void pointer is a generic pointer type, and capable of storing pointer to any type.

Q6.What is the minimum number of queues needed to implement the priority queue?

Two. One queue is used for the actual storing of data, and the other one is used for storing the priorities.

Q7.Which data structure is used to perform recursion?

The answer is Stack. Stack has the LIFO (Last In First Out) property; it remembers it's ‘caller’. Therefore, it knows to whom it should return when the function has to return. On the other hand, recursion makes use of the system stack for storing the return addresses of the function calls.
Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written explicit, stack is to be used.

Q8.What are some of the applications for the tree data structure?

1- Manipulation of the arithmetic expressions.
2- Symbol table construction.
3- Syntax analysis.

Q9.Which data strucutres algorithm used in solving the eight Queens problem?

Backtracking

Q10.In an AVL tree, at what condition the balancing is to be done?

If the "pivotal value", or the "height factor", is greater than one or less than minus one.

Q11.There are 8, 15, 13, and 14 nodes in four different trees. Which one of them can form a full binary tree?

The answer is the tree with 15 nodes. In general, there are 2^n-1 nodes in a full binary tree.
By the method of elimination:
Full binary trees contain odd number of nodes, so there cannot be full binary trees with 8 or 14 nodes. Moreover, with 13 nodes you can form a complete binary tree but not a full binary tree. Thus, the correct answer is 15.
comments powered by Disqus