Tag: cache

Computer Hardware – Memory : Static RAM Vs Dynamic RAM

2008-12-10

Random Access Memory plays a crucial role inside a computer. RAM is where the processor keeps the data it needs to work. The computer always has to load necessary data into the RAM because the speed of hard disks is very low for processor to work with.

Actually even the RAM is not fast enough for the processor so computers use many types of memories in different places such as cache or registers for different purposes. The purpose of this article is not to elaborate on how RAM works so without wasting time I will go into our topic.

Basically, there are two types of RAM which are Static RAM and Dynamic RAM. In this article we will compare these two types of RAM focusing on following aspects:

  • How these two types are designed
  • How these operate
  • Issues with each type
  • What is the most fast and what is most cost effective
  • Where these memories are used in our computers

Dynamic RAM

This is the most common type of RAM in use today. In a dynamic RAM chip, a bit is stored in a single memory cell. Each memory cell includes a transistor and a capacitor. Thanks to the revolution of technology these transistors and capacitors have become extremely small so that a single chip can hold millions of memory cells.

How these cells operate

In a memory cell, the capacitor holds electrons to store a binary 1. To store a binary 0, the capacitor is emptied. The transistor serves as a switch to allow the memory controller of the chip to read or change the state of a capacitor. In other words, the memory controller which is a circuit operates through the transistor to either empty the capacitor to store a binary 0 or to fill the capacitor with electrons to store a binary 1.

Problem with dynamic RAM

The problem with capacitors is capacitors have leakages so those can’t keep electrons for a long time without getting discharged. So in a dynamic RAM either the CPU or the memory controller has to recharge all capacitors which stores binary 1 before those get discharged (it’s not necessary to recharge capacitors which represents binary 0 because those capacitors are needed to be empty). This automatic refresh has to take place thousands of times per second. This refresh process takes time and therefore slows down all memory operations carried out on dynamic RAMs.

Static RAM

Static RAM stores a bit in a completely different mechanism called flip-flop which does not need a recharge. A flip-flop is an advanced yet interesting topic so keeping that for a future discussion I will publish only the definition of what is a flip-flop which I believe is enough to understand the scope of this article. A flip-flop is an electronic circuit that has two stable states and thereby is capable of serving as one-bit memory. Static RAM is made of an array or a collection of flip-flops.

Since flip-flops do not use capacitors, static RAM does not need to be recharged. So this property makes static RAM faster than dynamic RAM.

Ok now what’s wrong with Static RAM?

To implement a flip-flop it takes 4 or 6 transistors so Static RAM takes more space compared to dynamic RAM leading to a less memory per chip ratio and static RAM takes more electronic components than dynamic RAM to store a bit which then makes static RAM much more expensive than dynamic RAM.

Finally, where in my computer can I find these memories?

Since Static RAM is fast and expensive whereas Dynamic RAM is cheaper and slower, the speed sensitive cache area in the CPU is made of Static RAM while the large RAM area is made of comparatively cheaper Dynamic RAM.

Was this post helpful to you? How can I improve? – Your comment is highly appreciated!

Cassian Menol Razeek


C# ASP.NET – GridView : How to Keep Modified Data of Template Fields when Paging is Enabled?

2008-12-04

Today I had to take care of a problem of a certain company (CIS) that I consult. They had a problem of keeping the values modified in a template field of a gridview when the user moves from one page of the grid to another.

Template fields allow us to add custom columns into a datagrid or gridview. For an instance, we can add a grid column which has a textbox in each cell.

When the gridview has several pages, the gridview holds only the rows that are displayed in its Rows (collection) property. So we cannot access the values in other pages using the gridview.Rows property.

Then I thought that I could access the whole collection of rows by referring to the DataSource property of the gridview. This is a good idea because even though the gridview only shows the rows on the current page for display purposes, the data source property of the gridview holds the whole collection of rows in it.

ASP.Net clears the data source of any control at post backs. This is done to optimize performance of communications. In addition, the state of each control is stored in ViewState so it is not necessary to keep the datasource between postbacks.

The problem is worse now because I could not use both datasource and the direct row collection from the gridview.

Of course we can use either cache or session to keep the datasouce.


Session["DataSource"] = dt;  // store our table in the session

Then to synchronize (update) the datasource which was stored in the session we have to:

  • Go to each row in the gridview
  • Get the matching data row from the data table
  • Update the fields of the data table row

Since we have enabled paging for the gridview, we have to do this when ever user changes the page he/she is viewing to preserve his/her modifications.

So we need to write our code in the PageIndexChanging event handler of the GridView.

In my example I have two columns of the grid view called “ID” and “Name” and the name is the only template column I have used so I am only updating that column in the stored data table.

Code:


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// get the datatable from the
DataTable dTable = (DataTable)Session["dataSource"];

// now we will iterate through all rows of the grid
// then get the matching row from the data table (datasource of our grid)
// and append the updated data (by the user) to the selected data row
foreach (GridViewRow grv in this.GridView1.Rows)
{
// get the matching row from the data table
DataRow dRow = dTable.Rows.Find(this.GridView1.DataKeys[grv.RowIndex].Value);

// set values of updated columns : here I have only let the user to edit "Name" column
dRow["Name"] = ((TextBox)grv.FindControl("txtName")).Text;
}

// go to the next page of the grid
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataSource = (DataTable)Session["DataSource"];
this.GridView1.DataBind();

// show the whole collection of data in the second grid (used only to display)
this.GridView2.DataSource = (DataTable)Session["DataSource"];
this.GridView2.DataBind();
}

I have used a different gridview called GridView2 to show the whole data source without paging.

So don’t misunderstand the use of GridView2 in the last section of the code. It’s used only do display the whole set of data (without paging).

I cannot upload my code into this blog because it seems like zip files are not supported. If you like to take a glance of my code just add a comment so I’ll send the code to you via email.

Was this post helpful to you? How can I improve? – Your comment is highly appreciated!

Cassian Menol Razeek


  • Visitors Since Oct, 2008
  • Copyright © 1996-2010 I Learnt Today.... All rights reserved.
    iDream theme by Templates Next | Powered by WordPress