C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old January 5th, 2003, 10:51 AM
cemlouis cemlouis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 205 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 46 m 40 sec
Reputation Power: 0
Question Why we have to use pointers in memory allocation???

What is the idea of using pointers in memory allocation? I mean why we have to use pointers?

Reply With Quote
  #2  
Old January 5th, 2003, 11:59 PM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 594 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 14 h 6 m 15 sec
Reputation Power: 21
Think of the memory block as being your home.

Think of the pointer to the memory as your address or phone number.

Next time you need someone to come round to your house, try doing it without telling them the address.

Or try to send them a copy of your home.



The pointer is returned after a successful memory allocation.

It is the START of the memory block. It allows the SAME return value for all memory allocations irregadless of size, function used alloc /realloc /GlobalAlloc /new /far /calloc ect or data type.
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Reply With Quote
  #3  
Old January 6th, 2003, 02:14 AM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 8
Pointers are very useful. Once you get a handle on them, you'll realize they're pretty much everywhere, in every language, whether or not you handle them directly.

They allow you to defeat scope. Data can be initialized in one scope, and used in another. This may sound bad at first, but in has its uses, and often is needed. Without this, you need to use extensive use of globals, which is generally considered sloppy.

Similarly, they allow data to be exchanged across applications. You can't pass a variable from one app to another, since the second app doesn't have any concept of the first app's variables. Tell second app though where the data is (a pointer), and it can read it just fine. Exchanging data across apps isn't something you're likely to do at first, but today's software does it extensively. Take a look someday at all the different ActiveX, OLE, or COM controls installed on a recent Windows station: all of these work by one application hosting another and exchanging data.

Pointers allow structures/classes that wouldn't be possible with only member variables. Look into linked lists, or any type of node structure. They would lose alot of their functionality if they're forced to contain all data as member variables.

The list goes on.

Reply With Quote
  #4  
Old January 6th, 2003, 06:11 AM
cemlouis cemlouis is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 205 cemlouis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 46 m 40 sec
Reputation Power: 0
Thanx to you people... Now i understood...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Why we have to use pointers in memory allocation???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway