Lmi is sent between DCE and DTE in frame-relay for keep-alive purpose.
When LMI autosense is in effect , the dte first send three lmi messages one of each kind in response dce respond with single lmi and thus router and switch exchange the information.
sh frame lmi.
inverse arp frame-relay command enables dynamic frame relay mapping.
line console 0
For the pap neither the username nor the password are encrypted
Between the pap and chap ,chap uses the handshake similar to tcp ..thats why we use chap.
The port no used by the secure version of http is 443 where http port no is 80
WPA2 is the strongest wireless security protocol
At physical layer of the OSI model we should begin our network security policy just like locking devices.
Digital certificate is the tool that contains both private and public key.
Rip updates entries routing tables at every 30 sec
Four steps for rip
common config -register
the cause of line protocol dwn may be these three things
Dlci pronounced as del-see
Frame relay dlci’s are not advertised to any other router, making dlci’s locally significant only.
Frame relay communication is achieved by mapping this dlci to the remote router's ip address , and this can be done either dynamically or statically.
dynamic mapping means using inverse arp
At transport layer we deal with port no not ip address
No sequence field in udp header.
same field between tcp and udp header are
we use udp since its header is small so overhead is less.
BPDU serves as a keepalive for stp.
cisco switches will have all interfaces open by default.
privilege level 15 allows the user to telnet to a router without knowing the enable password.
eigrp and ospf both uses hello packets to keep adjancies alive
routing tables are kept in ram
The use of subinterface is commanly used to circumvent split horizon routing protocol rule.
The letter "P"next to a route in the EIGRP Topology table is good thing ie it means passive
In the cross over cable 4 wires actually cross over .
the lowest BIDS would win a root bridge election
by default Rip enable interface will send version 1 updates but receive version 1 n 2 updates.
ospf is not a Cisco-proprietary
PAP,multilink capabilites,dialer callback,CHAP are offered by ppp not by hdlc.
chap authentication will be attempted before pap
if the remote router isn't running chap, a pap authentication attempt will be made
The manager of a ppp connection is a LCP(link connection protocol)
pap sends a clear-text password across the wan
chap sends a hash result across the wan rather than a password.
bgp uses tcp port 179 to establish adjacencies
bgp uses the same logical grouping concept as EIGRP
BGP neighbors need not to be directly connected.
4 types of ospf routers
NBMA=it happens in the router .
BMA=it happens in the switch .
lmi (local management interface) performs keep alive and status messages bet DTE and DCE.
LAPF =link access procedure frame bearer services used in frame relay
vpn=virtual+private
Command Line Modes
IOS startup process
ospf is a open standard, not a cisco propriety
By default all hosts connected to the switch are in one large broadcast domain and each host is in its own collision domain
by default in switch all ur access ports belong to same vlan
to terminate ping
firewalls run at application layer
ipsec is application idependent ..
ipsec tunnel mode packet
the sending application pass data to the network subsytem of the computer.
the network sub sytem wraps that data in a tcp header it says what application it is destined to
the default value fo variance in eigrp is 1
Is RIP v2 classfull or classless?
CCNA: You want to perform a traceroute to a remote device.
There are two steps required to configuring ACL's
A job ID is a token used to identify jobs to shell builtins. Job IDs begin with the
When LMI autosense is in effect , the dte first send three lmi messages one of each kind in response dce respond with single lmi and thus router and switch exchange the information.
sh frame lmi.
debug frame lmi
inverse arp frame-relay command enables dynamic frame relay mapping.
line console 0
By configuring logging synchronous command you are telling the router to hold messages
exec-timeout 0 0. This diasbles the default inactivity time out of 5 min to 0 sec
exec-timeout min sec
For the pap neither the username nor the password are encrypted
Between the pap and chap ,chap uses the handshake similar to tcp ..thats why we use chap.
The port no used by the secure version of http is 443 where http port no is 80
WPA2 is the strongest wireless security protocol
At physical layer of the OSI model we should begin our network security policy just like locking devices.
Digital certificate is the tool that contains both private and public key.
Rip updates entries routing tables at every 30 sec
optional rip command
version2
no auto-summary
R(config)#router rip
R(config-router)#network 10.0.0.0
#version 2
#no auto-summary ie it will show 10.0.0.0/8 what we configure is /16
Four steps for rip
enable routing protocol
activate it on the interface
advertise directly connected networks
configure optional parameters
common config -register
0x2102 :the default. Router looks up for the startup configuration file in NVRAM and for valid IOS image in Flash.
0x2142 : Nvram contents are bypassed, startup configuration is ignored.
0x2100 : router boots to rom monitor mode.
any change that is made on the config-register will come into effect after reload only.
by default the order the router attempt to load the ios image
flash ,tftp server ,rom
the cause of line protocol dwn may be these three things
lack of clockrate from dce
frame relay mismatch
encapsulation mismatch
Dlci pronounced as del-see
They identify the connection at the datalink layer of the osi model
the diff bet dcli and other protocols is that there is only one single number in the dlci header . there is no specified source and destination dlci.
Frame relay dlci’s are not advertised to any other router, making dlci’s locally significant only.
Frame relay communication is achieved by mapping this dlci to the remote router's ip address , and this can be done either dynamically or statically.
sh frame map
dynamic mapping means using inverse arp
to disable inverse arp , run no frame-relay inverse-arp before opening the interface. If u configure frame relay on an interface and then open it ,inverse arp runs by default.
to configure static mapping
r#conf t
r(config)#interface s0
r(conifg-if)#encapsulation frame-relay
#no frame-realy inverse-arp
#frame map ip 200.1.1.2 122 broadcast here 122 is local dlci
#frame map ip 200.1.1.3 123 broadcast
At transport layer we deal with port no not ip address
No sequence field in udp header.
same field between tcp and udp header are
source port,dest port no and cksum field.
we use udp since its header is small so overhead is less.
BPDU serves as a keepalive for stp.
cisco switches will have all interfaces open by default.
privilege level 15 allows the user to telnet to a router without knowing the enable password.
eigrp and ospf both uses hello packets to keep adjancies alive
routing tables are kept in ram
The use of subinterface is commanly used to circumvent split horizon routing protocol rule.
The letter "P"next to a route in the EIGRP Topology table is good thing ie it means passive
and it can be used to transport data.
In the cross over cable 4 wires actually cross over .
the lowest BIDS would win a root bridge election
by default Rip enable interface will send version 1 updates but receive version 1 n 2 updates.
Access-list 3 deny ip 172.12.12.1 0.0.0.0
One line acl is an explicit deny it is going to deny everything.it is a standard acl .ip address is source ip add
ospf is not a Cisco-proprietary
PAP,multilink capabilites,dialer callback,CHAP are offered by ppp not by hdlc.
imp command
debug ppp negotiation
debug ppp authentication
R(config-if)#ppp authentication chap pap
means
chap authentication will be attempted before pap
if the remote router isn't running chap, a pap authentication attempt will be made
The manager of a ppp connection is a LCP(link connection protocol)
pap sends a clear-text password across the wan
chap sends a hash result across the wan rather than a password.
bgp uses tcp port 179 to establish adjacencies
bgp uses the same logical grouping concept as EIGRP
BGP neighbors need not to be directly connected.
mandatory bgp attributes are AS_PATH ,ORIGIN,and NEXT-HOP
discretionary bgp attributes are local pref and atomic aggregate.
The three possible values for a bgp origin code are i ,e and ?
i=path originated from igp
e=path originated from egp
?=origin is not clearie leraned by redistribution
In bgp best path selection process ,local pref is used first on the non-cisco router but for the cisco router weight is the attribute.and weight is locally significant only.
bgp stimes requires session and adjacienses to be reset to make changes comes into effect without tearing the the network for that we use soft reset.
octo cable is used to connect the access-server and router .
sh int trunk
sh int e0
4 types of ospf routers
internal routers= are routers whose interfaces are all in the same area.
ABR= will have atleast one interfaces in area 0, and connect other areas to area 0.
backbone router=are routers with atleast one interface in area 0.so all abr's are backbone routers but all backbone routers are not abr's.
autonomous system border router= takes routes from other protocols and place them into the ospf domain. this process is called the route distribution.
NBMA=it happens in the router .
BMA=it happens in the switch .
lmi (local management interface) performs keep alive and status messages bet DTE and DCE.
LAPF =link access procedure frame bearer services used in frame relay
it is a layer 2 encapsulation for the frame relay.
lapf header+type field=ip packet+lapf trailer
for novell ipx
network = 32 bits
host or node =48 bits
for apple talk
network= 16bits
host=8bits
for decnet
network=6 bits
host=10bits
these all are fixed
but the ip is not fixed
0.0.0.0 is a broadcast address
if u want to configure 1-12 port to vlan148
then
S(config)#interface range fas1/0/1 - 12
#switchport mode access
#switch access vlan 148
process id in ospf is local to the router and does not need to match the other router.
wildcard mask is used to match the ip address that is used in the interface
we can match whole network of which ip address of int is a part.
router examine the ip add of directly connected int and activate ospf on these int.
we can use wild card mask 0.0.0.0 to match exact address.
vpn=virtual+private
virtual in the sense information is transported over the public network
private the traffic is encrypted to keep the data confidential
benefits cheap and scalable
Command Line Modes
-user exec
-privileged exec
MODES
-interface configuration
eg ip address ,subnet masks ,change speed,clock rate ,duplex,bandwidth ,layer 2 encapsulation,changes made here only effect the interface
-Line configuration
eg is used for line setup modes. Line includes console ,tty,dtty,aux,console and args line are local to the administration,tty lines are synchronous serial connection usually for analog dialup connection to the modem,vty line are virtual connection for telnet to the router
-router configuration
eg is used for dynamic routing configuration such as rip ,eigrp,ospf,
IOS startup process
The basic steps are
1.Run the post
2.Find the IOS
3.Load the IOS to RAM
4.Find the configuration
5.Load the configuration to RAM
first POST run then bootstrap check for startup config in nvram for boot system command.if boot system command is not found then the router looks for the first valid IOS image in flash memory....if there is no usable ios in flash the router will begin broadcast for tftp
server hoping to find ios image it can download and use and if no tftp server is connected or no valid ios is found then router will load rx buid many ios this ios has a valid fimilar ios which can be full ios the main purpose of this is to allow you to manually connnect to the tftp server to download any valid ios to flash.if rx build fails the router will load to rom monitor ...rom mon also can connect to the tftp server...rom mon command vary with hardware type..here the router looks for startup file in nvram and this is copied to ram and renamed as running config..if there is no start up config in nvram ..the router will broadcast for tftp server to see if there is configuration file if that fails then it lead to set up mode ... in most device ios image is decompressed and copied to ram to run from there ...simi nvram is copied to ram and called running-config.
ospf is a open standard, not a cisco propriety
it is link state routing protocol ,means updates are send whenever there is change in link topology.
there are two optional commands for ospf config on interface
1.ip ospf priority priority_number
to change the priority of an interface to become dr and bdr manually
2.ip ospf cost
to change the cost manually fo an interface
other command are
sh ip ospf interface
it displays area id ,dr/bdr
debug ip ospf events
to troubleshoot why routers are not forming neighbourhood
By default all hosts connected to the switch are in one large broadcast domain and each host is in its own collision domain
by default in switch all ur access ports belong to same vlan
the trunking ports will not be shown in sh vlan brief
to have a inter vlan communication there should be router in the middle ie either use a technique router on a stick or use a layer 3 switch for that switch.
to terminate ping
crtl+shift+6 twice
spf and dijsktra are the same algorithm.
in a hub and spoke topology to make hub dr make its interface priority 1 and make the interface priorities of the hubs as 0.
following ospf neighbour adjacencies states inorder are ..
down
attempt
exstart
init
2 way
exchnage
loading
full
authentication runs at layer 7
firewalls run at application layer
ipsec provides
-authentication
-integrity
-confidentially
ipsec protected packet
data+tcp header+ipsec+ip header
ipsec is application idependent ..
ipsec tunnel mode packet
data+tcp header+ip HEADER+IPsec HEADER+ip header
the sending application pass data to the network subsytem of the computer.
the network sub sytem wraps that data in a tcp header it says what application it is destined to
ip header wraps tcp header
then we use ipsec for encryption and authentication
again ip header
ip header is all about determining where the data should go in the physical network so its for data passing from point a to point b.
the default value fo variance in eigrp is 1
sh ip protocols is the command to verify this.
active in eigrp means its currenlty calculated by the eigrp routing algorithm so it can't be used to route data.
advantage
Is RIP v2 classfull or classless?
Classless means that the subnet informtion is sent out with
the route updates and RIPv2 does this so it is classless.
CCNA: You want to perform a traceroute to a remote device.
Which of the following will a Cisco router accept:
trace - yes
tracert - no this is a Windows command
traceroute - yes
There are two steps required to configuring ACL's
1.create the ACL and add permit/deny rules
2.Apply the ACL to an interface inbound or outbound.
config#access-list 101 permit tcp host 192.168.1.10 host 192.168.2.10 eq 22
config-if #ip access-group 101 out
clock rate is applied on serial interafce
channel group is applied on the int
A job ID is a token used to identify jobs to shell builtins. Job IDs begin with the
%
character; %n
identifies job n, while %%
identifies the current job. Other job IDs are specified by POSIX
The job id is a sequential number assigned to the processes associated with the current shell you are running. The first one you launch is 1, the second one is 2, and so forth.
In computing, the process identifier (normally referred to as the process ID or just PID) is a number used by most operating system kernels (such as that of UNIX, Mac OS X or Microsoft Windows) to (temporarily) uniquely identify a process. This number may be used as a parameter in various function calls allowing processes to be manipulated, such as adjusting the process's priority or killing it altogether.
In Unix-like operating systems, new processes are created by the fork() system call. The PID is returned to the parent enabling it to refer to the child in further function calls. The parent may, for example, wait for the child to terminate with the waitpid() function, or terminate the process with kill().
In Unix-like operating systems, there are two tasks with specially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, and is actually part of the kernel rather than a normal user-mode process. Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. Originally, process ID 1 was not specifically reserved for init by any technical measures: it simply had this ID as a natural consequence of being the first process invoked by the kernel. More recent Unix systems typically have additional kernel components visible as 'processes', in which case PID 1 is actively reserved for the init process to maintain consistency with older systems.
Under Unix, process IDs are usually allocated on a sequential basis, beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases. In Mac OS X and HP-UX, allocation restarts at 100. However, for this and subsequent passes any PIDs still assigned to processes are skipped. Some consider this to be a potential security vulnerability in that it allows information about the system to be extracted, or messages to be covertly passed between processes. As such, implementations that are particularly concerned about security may choose a different method of PID assignment.[1] On some systems, like MPE/iX, the lowest available PID is used, sometimes in an effort to minimize the number of process information kernel pages in memory.
Under Microsoft Windows operating systems, one can get the current process' ID using
In Unix-like operating systems the current process ID is provided by a
In Unix and other computer multitasking operating systems, a daemon ( /ˈdeɪmən/ or /ˈdiːmən/)[1] is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH connections.
In a Unix environment, the parent process of a daemon is often (but not always) the init process (PID=1). Processes usually become daemons by forking a child process and then having their parent process immediately exit, thus causing init to adopt the child process. This is a somewhat simplified view of the process as other operations are generally performed, such as dissociating the daemon process from any controlling tty. Convenience routines such as daemon(3) exist in some UNIX systems for that purpose.
Systems often start (or "launch") daemons at boot time: they often serve the function of responding to network requests, hardware activity, or other programs by performing some task. Daemons can also configure hardware (like udevd on some GNU/Linux systems), run scheduled tasks (like cron), and perform a variety of other tasks.
Types of daemons
DETAILED STEPS
In computing, the process identifier (normally referred to as the process ID or just PID) is a number used by most operating system kernels (such as that of UNIX, Mac OS X or Microsoft Windows) to (temporarily) uniquely identify a process. This number may be used as a parameter in various function calls allowing processes to be manipulated, such as adjusting the process's priority or killing it altogether.
In Unix-like operating systems, new processes are created by the fork() system call. The PID is returned to the parent enabling it to refer to the child in further function calls. The parent may, for example, wait for the child to terminate with the waitpid() function, or terminate the process with kill().
In Unix-like operating systems, there are two tasks with specially distinguished process IDs: swapper or sched has process ID 0 and is responsible for paging, and is actually part of the kernel rather than a normal user-mode process. Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. Originally, process ID 1 was not specifically reserved for init by any technical measures: it simply had this ID as a natural consequence of being the first process invoked by the kernel. More recent Unix systems typically have additional kernel components visible as 'processes', in which case PID 1 is actively reserved for the init process to maintain consistency with older systems.
Under Unix, process IDs are usually allocated on a sequential basis, beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases. In Mac OS X and HP-UX, allocation restarts at 100. However, for this and subsequent passes any PIDs still assigned to processes are skipped. Some consider this to be a potential security vulnerability in that it allows information about the system to be extracted, or messages to be covertly passed between processes. As such, implementations that are particularly concerned about security may choose a different method of PID assignment.[1] On some systems, like MPE/iX, the lowest available PID is used, sometimes in an effort to minimize the number of process information kernel pages in memory.
Under Microsoft Windows operating systems, one can get the current process' ID using
GetCurrentProcessId()
API,[2] and ID of other processes using GetProcessId()
API.[3] Internally, process ID is called a client ID, and is allocated from the same namespace as thread IDs, so these two never overlap. The so-called System Idle Process is given process ID 0, and System Process is given process ID 4.In Unix-like operating systems the current process ID is provided by a
getpid()
system call, or as a variable $$
in shell. The process ID of a parent process is obtainable by a getppid()
system call.In Unix and other computer multitasking operating systems, a daemon ( /ˈdeɪmən/ or /ˈdiːmən/)[1] is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH connections.
In a Unix environment, the parent process of a daemon is often (but not always) the init process (PID=1). Processes usually become daemons by forking a child process and then having their parent process immediately exit, thus causing init to adopt the child process. This is a somewhat simplified view of the process as other operations are generally performed, such as dissociating the daemon process from any controlling tty. Convenience routines such as daemon(3) exist in some UNIX systems for that purpose.
Systems often start (or "launch") daemons at boot time: they often serve the function of responding to network requests, hardware activity, or other programs by performing some task. Daemons can also configure hardware (like udevd on some GNU/Linux systems), run scheduled tasks (like cron), and perform a variety of other tasks.
Types of daemons
In a strictly technical sense, a Unix-like system process is a daemon when its parent process terminates and it is therefore 'adopted' by the init process (process number 1) as its parent process and has no controlling terminal. However, more commonly, a daemon may be any background process, whether a child of init or not.
The common method for a process to become a daemon involves:
- Dissociating from the controlling tty
- Becoming a session leader
- Becoming a process group leader
- Staying in the background by forking and exiting (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal execution. This idiom is sometimes summarized with the phrase "fork off and die"
- Setting the root directory ("/") as the current working directory so that the process will not keep any directory in use that may be on a mounted file system (allowing it to be unmounted).
- Changing the umask to 0 to allow open(), creat(), et al. calls to provide their own permission masks and not to depend on the umask of the caller
- Closing all inherited open files at the time of execution that are left open by the parent process, including file descriptors 0, 1 and 2 (stdin, stdout, stderr). Required files will be opened later.
- Using a logfile, the console, or /dev/null as stdin, stdout, and stderr
----------------------
snmpd - daemon to respond to SNMP request packets.
snmpd is an SNMP agent which binds to a port and awaits requests from SNMP management software. Upon receiving a request,
it processes the request(s), collects the requested information and/or performs the requested operation(s) and returns the
information to the sender.
sshd (SSH Daemon) is the daemon program for ssh(1). Together these programs replace rlogin and rsh, and provide secure
encrypted communications between two untrusted hosts over an insecure network. The programs are intended to be as easy to
install and use as possible.
sshd is the daemon that listens for connections from clients. It is normally started at boot from /etc/rc It forks a new
daemon for each incoming connection. The forked daemons handle key exchange, encryption, authentication, command
execution, and data exchange. This implementation of sshd supports both SSH protocol version 1 and 2 simultaneously. sshd
works as follows.
The show processes cpu command displays information about the active processes in the router and their corresponding CPU
utilization statistics. The following is a sample output of the show processes cpu command:
SUMMARY STEPS
1. show watchdog memory-state location node-id
1. show processes memory [job-id] location node-id
2. show memory job-id
3. show process memory job-id
4. show memory compare start
5. show memory compare end
6. show memory compare report
7. Contact Cisco Technical Support if the problem is not resolved.
DETAILED STEPS
Command or Action
Purpose
Step 1
show watchdog memory-state location node-id
Example:
RP/0/RP0/CPU0:router# show watchdog memory-state location 0/RP0/CPU0
Displays the memory state for the node. If the node is not in the normal state, proceed to Step 2 to list top memory users
and identify possible memory leaks.
Step 2
show processes memory [job-id] location node-id
Example:
RP/0/RP0/CPU0:router# show process memory location 0/RP0/CPU0
Displays information about the text, data, and stack usage for all active processes on a specified node.The output lists
top memory users and identifies possible memory leaks. When top memory users have been identified, note the job ID and use
the memory usage analyzer to discover the processes causing a memory leak. See Step 5 through Step 7 for how to use the
memory usage analyzer.
Step 3
show memory job-id
Example:
RP/0/RP0/CPU0:router# show memory 123
Displays the available physical memory and memory usage information of a specific process.
Step 4
show process memory job-id
Example:
RP/0/RP0/CPU0:router# show process memory 123
Displays information about the text, data, and stack usage for a specific process.
Step 5
show memory compare start
Example:
RP/0/RP0/CPU0:router# show memory compare start
Takes the initial snapshot of heap memory usage for all processes on the router and sends the report to a temporary file
named /tmp/memcmp_start.out.
Step 6
show memory compare end
Example:
RP/0/RP0/CPU0:router# show memory compare end
Takes the second snapshot of heap memory usage for all processes on the router and sends the report to a temporary file
named /tmp/memcmp_end.out. This snapshot is compared with the initial snapshot when displaying the heap memory usage
comparison report.
Step 7
show memory compare report
Example:
RP/0/RP0/CPU0:router# show memory compare report s
Displays the heap memory comparison report, comparing heap memory usage between the two snapshots of heap memory usage.
Step 8
Contact Cisco Technical Support.
If the problem has not been determined and is not resolved, contact Cisco Technical Support. For Cisco Technical Support
contact information, see the "Obtaining Technical Assistance" section in the Pre
Show context and clear context
The clear context command provides the ability to clear the information displayed by the show context commands on the
Cisco 12000 series Internet Router (formerly known as the GSR).
The affected "show" commands are:
•show context slot
•show context all
•show context summary.
Note The clear context command does not clear output for the show context command when entered with no arguments.
Information Displayed by the Show Context Commands
The show context commands display the following information (this information is cleared with the clear context command):
•Reason for the system reboot
•Stack trace
•Software version
•The signal number, code, and router uptime information
•All the register contents at the time of the crash
Benefits
The clear context command allows technicians and customers to clear information displayed by the show context commands.
After the data is cleared, only information from any new crashes will appear. This allows users to display only the most
recent and relevant information.
Restrictions
The clear context command does not clear the show context output when show context is entered with no arguments.
---------------------------------------
Heap memory
Heap memory is a region of a computer's memory (RAM - Random Access Memory) that is used for dynamic memory allocation. Unlike the stack, which is used for static memory allocation and follows a last-in, first-out (LIFO) model, heap memory allows for dynamic memory allocation and deallocation in a more flexible manner.
Here are some key characteristics and aspects of heap memory:
1. **Dynamic Memory Allocation:**
- Programs often need memory for data that is created during runtime and whose size may not be known at compile time. Heap memory allows dynamic allocation of memory for such data structures.
2. **Manual Memory Management:**
- Memory in the heap is typically managed manually by the programmer (in languages like C and C++). The programmer is responsible for allocating memory when needed and releasing it when it's no longer required.
3. **Heap Allocation Functions:**
- In languages like C and C++, memory in the heap is allocated using functions like `malloc()`, `calloc()`, or `new`, and deallocated using `free()` or `delete`.
Example in C:
```c
int *arr = (int *)malloc(5 * sizeof(int)); // Allocating memory for an integer array
free(arr); // Deallocating the memory when done
```
4. **Dynamic Data Structures:**
- Heap memory is often used for dynamic data structures such as linked lists, trees, and dynamic arrays where the size can change during program execution.
5. **Non-Contiguous Memory:**
- Unlike the stack, which is typically managed as a contiguous block of memory, the heap is often non-contiguous. Memory blocks are allocated as needed, and they may not be adjacent to each other.
6. **Garbage Collection (in Managed Languages):**
- In managed languages like Java, C#, and Python, heap memory is used for objects, and memory management is handled by a garbage collector. Garbage collectors automatically identify and reclaim memory that is no longer in use.
7. **Memory Leaks:**
- Improper management of heap memory can lead to memory leaks. A memory leak occurs when memory is allocated but not deallocated, resulting in the gradual consumption of available memory over time.
8. **Heap Overflow and Heap Underflow:**
- Similar to stack overflow and underflow, heap overflow occurs when a program writes more data to a memory block in the heap than it allocated, potentially leading to unpredictable behavior. Heap underflow occurs when a program reads data before the start of a memory block.
Understanding and managing heap memory is crucial for developing efficient and reliable software, especially in languages that provide manual memory management. In contrast, languages with automatic memory management (garbage collection) help alleviate some of the challenges associated with manual heap memory management.
No comments:
Post a Comment