<< Chapter < Page Chapter >> Page >

Today, even assembly programmers do not have to worry about memory allocation because the assembler will handle that. The memory allocation programs are good enough at solving the problem that it isn't worth a programmer's time to solve this problem. Instead, there are a few different ways that languages solve the problem of memory allocation. In general, it is a simple matter to provide the programmer with the memory that is known to be needed at compile time. This includes primarily global data values and the space for the code itself. The more difficult problem is how to provide flexible data memory that may or may not be needed when the program actually executes.

The approach that C takes is to ask the programmer to call special functions that manage memory allocation. These methods are called malloc(int) and free(void *) The basic idea is that whenever the program needs a specific amount of additional memory, it calls malloc (memory allocate) with the integer being the number of bytes of memory needed. The program will then search for a block of memory of the appropriate size and return a pointer to it. When the program is done with a particular allocation of memory, it calls free to let the memory management library know about the particular block of memory isn't needed anymore. If the programmer is diligent about returning (freeing) memory that isn't needed anymore, then the programmer will enjoy abundant memory without having to count individual bytes. On the other hand, if a program repeatedly requests memory but does not free the memory back to the system, the memory allocator will eventually run out of memory. The program will then crash. Thus, it is essential for passages of code that frequently request memory allocations to free these allocations as they can. Un-freed allocations are not fatal in very infrequently executed parts of code; however, the longer a program runs, the more the problem will accrue. In general, a program that allocates but does not free memory, gradually using unnecessarily more memory over time, is said to have a memory leak .

Other languages handle the problem of memory allocation automatically. Java will allocate the memory for new data on the fly using the keyword new instead of the function malloc, but the more important difference is that freeing takes place automatically. Part of the Java system called the garbage collector detects memory that can be safely freed and does so. In this fashion, Java programs do not suffer memory leaks in the way a C program might.

Memory and the msp

In the MSP430 there is no inherent difference between instruction memory, data memory, and heap memory. The only subdivisions in memory are the blocks of flash and the section of RAM. Any of these sections can hold instructions or other kinds memory. However, because it is problematic to erase and rewrite flash in the middle of program execution, the flash memory is best saved for instructions and constants. The remaining RAM must be shared between the heap, the dynamically allocated memory, and the global variables. On the MSP430F169, there is only 2KB of RAM, so no memory leaks are tolerable.

How memory is wasted or conserved

Memory leaks, the most notable way to waste memory, have already been discussed, but there are several others. While memory leaks abuse the dynamically allocated portion of data memory, many layers of function calls abuse the heap. Above, it was explained that each time a function calls another function, the caller's registers and data are moved onto the heap. If each called function calls another function in turn, then the heap portion of the memory will grow significantly. For high power computing systems, this is not usually a great threat to the overall supply of memory compared to memory leaks. Embedded systems however must avoid deep layers of function calling or risk exhausting the overall supply of memory.

There is also a programming technique called recursion wherein a recursive function calls itself repeatedly on progressively smaller or simpler versions of the data until the answer is trivial. While this technique leads to some very clever solutions to some complex problems, it is uses large amounts of memory to achieve this end. Therefore, recursion is generally a poor choice when memory must be conserved.

Finally, another important way to waste memory is to create too many global variables. Specifically, variables whose scope could be local or who could be allocated dynamically waste memory because they take up space even when they aren't being used. Use malloc and free to avoid using as many global variables.

Questions & Answers

can u please include methods of psychology
Krishna Reply
Naturalistic Observation Laboratory Observation Case Studies
Cindy
why sibblings are so different? (physical and emotional) is it due to a bio or social fact?
Camilo Reply
It's due to their bio
mboya
social fact can also effect their emotional because very man have different feel from around.
AHMAD
no Hindi psychology
SERAJ
importance of teaching and learning?
Lerato Reply
we need to know the human mind and behavior and how it works. this can make us successful in our jobs because we know what to do to please the people or to catch them lying etc.
carolline Reply
is a Greek word for soul
carolline
scientific study of the human behavior
carolline
Humans are extremely inconsistent at catching out liars. Human intuition and lie detection methods are prone to all kinds of biases. Always follow the evidence and don't let your emotions influence your rationality.
Leon
hello everyone, i was just wondering i have to pick a theoretical perspective to describe a mental disorder, i have picked Anti social personality disorder and was going to use the biomedical model to explain it. does anyone here regard aspd as a neurobiological disorder? kind regards.
niamh Reply
is anti social personality disorder a neurobiological illness?
niamh
rationalisation, displacement and reaction formation
Mary Reply
only a perspective of what we have pursued till now as an experience
Priyank
what is the meaning of pysche?
Christine Reply
The meaning of psyche is Mind
Jobin
Friends can anyone please tell me, why the study of psyche is so important?
Jobin
Well in Greek, it means "soul, spirit, the mind, or the invisible animating entity which occupies the physical body".
Friends can anyone please tell me, why the study of psyche is so important?
Jobin
Friends please tell me how to counsel a student who does not want to change their lives but are comfortable in the same life situation?
Jobin
I think it's such an important study because it's one if those rare things that can't be understood in the conventional manner. The mind (not the brain, but the soul and spirit), cannot be studied physically, or through the use of sight, touch, smell, taste, or hearing.
Much focus and attention would have to be put into it to understand it, and it can't be fully understood because everyone's different and subjected to different circumstances, and we live an ever-changing world. It's important because it helps to develop spiritual, mental, and emotional intelligence
is humanities a good stream? is there scope for a subject like psychology in the future. is it a good choice?
amrita Reply
is humanities a good subject?
amrita
Sure it is.
Jobin
you gonna opt for humanities as long as you don't want to pursue psychology in BSc honours , you'll be able to pursue BA psychology only. So if you want to pursue BSc then go for Science stream only.
Priyank
Morning everyone. How can you help a person who can't stop musterbating?
Ntando Reply
find a different activity to divert the need to masturbate
vincent
masturbation is a need u cant stop it
Abhilash
Try positive punishment then transition to negative punishment
Atone
It probably has something to do with the environment one grew up in and their genetics that caused their puberty to have this psychological effect on them.
Atone
trying to keep yourself busy with stuffs you love doing the most.like reading or listening to music or sports
Naomi
addiction and attachment issues do go hand in hand
vincent
stop watching pornography if you do; it leads you to fantasizing via masturbation. If you are a Christian, try indulging is spirituality (music and prayrer) before your bed time.
Matovu
don't stop watching anything but instead pay attention to yourself and be conscious enough of what happens inside your brain or how the thought process goes that leads you to masturbating
Priyank
Hello everyone have a nice day
Mary
Hello
Georgescu
internal for example a times when when I watched a pornography movie I end up thinking about it a lot so what I used to stop it is to create something in my mind that can ever exist in real life. I can create a story for about a week in my mind just to forget about it and it actually helps me
Mary
@mary charm story construction is helpful but then it open up on doorways for a new problem or addiction per say since it gives boost to the overexaggeration of reality which is not right, instead try to jot down what do you feel, be it digitised or normal writing. painting it also helps.
Priyank
she**
vincent
Marriage is the only solution guys.You can't do it if you get 'it'
Philip
I agree philip Nyenze. in addition to self control
Diamly
Hello y'all! I'd like to start by saying, Marriage isn't a solution for everyone. We all have differences across the board, mental, spiritual and physical. Personally marriage has fixed it for me but not for the reason you'd think. In fact the complete opposite. I found myself with a partner who's..
Samwell
... spiritual views and mental issues (depression) caused my partner to be very distant physically and it caused so much heartbreak and pain within myself and in turn made my mental health to whirlwind out of control. it took 4 years to get through it but I concentrated on my love for my partner...
Samwell
.... outside of the bedroom because I wanted them completely. through trials and error I think I finally got myself in a good place. I don't need to masturbate because even though the hormones are rushing within me and I want to tackle my partner down, my soulmate shines through brighter than that..
Samwell
... gorgeous body.
Samwell
You have to stop thinking about the filling that u can get from musturbation and get a partner if only you are 18 years and above.
Tanam
Unless it's a chronic problem like they are addicted to it and do it all the time, then let them be. Masterbation is a natural thing there's nothing wrong with it and it has many health benefits. As long as it isn't a chronic case they're be fine.
UnhealthyCopingMecha
how natural is it?...this i just a formed habit. it takes 3weeks(21)days to form an habit...if youve done it more than 21days,admit its your habit...same it can take 21days to end a formed habit.if you've wanted to stop this habit,contact me personally i'll guide you through
Philip
I'd give them heavy doses of SSRI's and SSNI and toss is a few antipsychotics. first generation.
Sadie
try to busy if you have not free time you will not do . also read all the disadvantage of it.
AHMAD
hi how to join conversation?
Jason Reply
i don't know
Azeneth
How can you say that your bestfriend is true to you?
Azeneth Reply
why is my mom so mean?
Krista Reply
Hello Krista! Idk what made you think that ur mom is mean, but trust me, that's just not true. She really loves u and cares for u, but it's just that her way of caring is different than others. Ik it sounds mean, but deep inside her heart, she loves u a lot, just like all moms love their children.
Drazy
perhaps, but if you could elaborate on what exactly she does that is demeaning, because sometimes some lessons that are best learned are through a tough and disciplined manner, most likely she really loves you and wants you to learn the lesson once, so you won't have to find it out the hard way
Eldar
I have been assigned to an emotional disturbed student. She seemed fit first but you notice she interrupts or teases other students.would you work with this student an class to improve the situation?
Saleem
Hello ! I think that she's kind of person that shows her bad side before the good. In other words "if you gonna love me ,first you should accept my bad side" These kind of person have the purest love ,once you get through their bad side , it demand some patience and emotional control but , It worth.
aziz
difficult question...ask from your father
Farhat
We can't know for sure. Whatever decisions your mom makes at the time are her best choices to fulfill her needs, in a way, so her meanness probably in relation to her own prioritization of needs, upbringing, temperament.
frootloop
Also, it's likely part of who you are, as well. By growing up with her, you're likely more vulnerable to her attacks, and they trigger you easily. These are both things that could potentially change, but not without a lot of work
frootloop
Hope this helped! I'm no therapist or psychologist, so take what I say with a grain of salt
frootloop
Rge only one onbthis planet have the ability to be with u whatever happens
Mohammed
What is the relationship between physical development and motor development
philip Reply
what is memory
Devyani Reply
the faculty by which the mind stores and remembers information. "I've a great memory for faces" something remembered from the past; a recollection.
Amber
what is the difference between Counsellor and Psychologist?
KADIR
One talks you through your problem helping you solve them on your own (and vent out). The other writes a prescription for you and diagnoses the medical issue lying beneath (eg depression, anxiety)
Vasu
A psychologist has been trained to look at behavioural aspect of mental problems rather than look at biomechanical perspectives. He is more likely to ask his patient about his past and his present behavior, his feelings and his problems to arrive at the root cause.......Read more
Miraj
psychologists have a better understanding and awareness of behavioural reasons of mental problems than others.
Miraj
Instead of the behavioural approach adopted by psychologists, a counsellor tries to encourage the patient to direct the treatment session. He creates an environment where the patient is able to clearly see through his own problems and the reasons underlying these problems........Read more
Miraj
Thus, without relying anybody else, the patient is able to overcome his problems. In a broader sense, both psychologists and counselors both are specialists who try to solve mental problems of people through adopting different approaches.
Miraj
@Kadir shuaib, I hope you understand l
Miraj
Thanks to bits@Miraj Gillani But I've told that Counselling is applied psychology and counseling only effective when theory is applicable.
KADIR
@kadir👍
Miraj
A memory is a faculty which permits human to situate his actions and his state in the times and space.
Sinaly
@vasu a psychologist can't give you a drug as a prescription, that's the job of a psychiatrist
Argoncor
hi I have dealing with a lady who is severely depressed .. she gets suicidal attacks even at the thought of her mother in law . I am working on realeasing her stress .. any other suggestions?
Sriya
hi sriya.. try engazing her in some activity...like cooking,or any u like...make ppl appriciate her effort...plan such that one or other alawys keep appreciating her efforts...that will bring value to her own existence...but it will definetly take some time so u must have patience. tke cre champion.
ARJUN
ARJUN great idea.
Cindy
Hey Sriya! U can take her 2 sum place where she can inhale some fresh air&feel good.&when she gets suicidal attacks 'bout her mom-in-law,u can try calming her down by saying that her mom-in-law wud also appreciate her works&she wud b sad if she knew that her daughter in law is unhappy.Gud luck,girl!
Drazy
Idk about Drazy's comment, something that worked for me was to defy irrational thought patterns and watch out for them to defuse your own suicidal thoughts. Maybe find a focus to life completely independent of the MIL
frootloop
Sriya she needs to do something that makes her happy. I used to spend time with a depressed lady I ask her if anything helped her. when she had anxiety attacks she said music. Whenever I could feel her starting to have an attack I'd hand her head phones along with her favorite music.
Cindy
I asked her she said her husband she has anchored her entire happiness with her husband. she can't even move without him
Sriya
I apologize Sriya I just joined the conversation, I don't know about her husband ; therefore I am not able to give suggestions.
Cindy
@sriya you need to give her an insight about her own individuality so she could seperate herself mentally from her husband and see for herself what she is and where she is! you need to make her understand this that her husband and she herself are two both seperate individuals, may be meditation....
Priyank
...can give her a new tangent to think and pursue reality as it, I use meditation alot on my clients to give them a fresh perception of reality...
Priyank
Hi
ABUBAKAR
Excellent point Priyank
Cindy
thank you everyone I think I know what to do ..
Sriya
Maybe there's a dependency on the husband, and has a bearing on the lady's relationship with her MIL? Like, her MIL is threatening to her
frootloop
Exactly frootloop. Similar to changing a negative thought to a positive thought.
Cindy
What is the deference between Counseling and Psychology?
ABUBAKAR
I think Cindy and Arjun's answers are great. I'm no specialist, but having something private that she's not at war with and can appreciate (activity, hobby, music, etc) could definitely be helpful
frootloop
hey mates..we r part of d universe and essence of universe is continuous activity..even stagnant water fouls..depresn over d top take self value...hence engazin in some purpose oriented work(activity )along with fellows appriciation(value) is two pronged strategy. but it all takes time.u need to b
ARJUN
smart n patience..as depressions dosnt have a face..!!! love u all
ARJUN
always make her to feel important
Mary
@First know the root cause of the issues she's been traumatized with..talk to her in her own language without any Prejudice let her confide in you then you can get the solutions...as the primary reason for depression is being lonely around your own people and house..an open ear to listen to ur silly
harvey
... stories piled up urges, desires a warm hug that human touch we loose over time... saying is easy but living in it is insane..we all need someone to dump our day with..make her realize the consequences if she does hurt herself or others..as u cannot be with them 24/7 so try instilling the...
harvey
...SELF ESTEEM AND BELIEF which she lost over time to her own people..ask her to do some activities which will earn money online and are fun while doing so...keep herself busy not sit and overthink on things!
harvey
Sriya. Give her a story.where you passed the same. If you dont have your own story,then create one. As you give the fake story you tend get more into her shooes.,such that u feel as if u had once being stressed and u overcame it.Make the story bitter that she even symphathizes with u.
Philip
....this way,your patient trusts you more. They believe if they do whatever u tell them they Must overcome their situations....i once told a patient,"if you feel urine and hold on for atleast 2hrs,u will forget all that"...he believed tht so he always drink alot of water to create the urge to urinat
Philip
...he started focusing on how to create urine in his bladder,and he forgot all tht was disturbing.....i nicknamed him "fish."...and am working a theory on the same case. i will post "The Fish theory" once am done with it...though i might change its title,....
Philip
importance of social psychology in the domain of education
solang Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?

Ask
Danielrosenberger
Start Quiz