473,785 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

memory use

In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};
Nov 14 '05 #1
12 1722
Jim
On 25 Oct 2004 23:34:54 -0700, mi*****@clift.c om.au (Michael) wrote:
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};


The compiler is not even obliged to use a stack!

Jim
Nov 14 '05 #2
>In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.
(1) what stack?
(2) which stack?

Standard C is not required to use a stack.
However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?
How did you determine this from the code below, or, for that
matter, using any portable code?
And what difference does it make?
if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};


Gordon L. Burditt
Nov 14 '05 #3

"Michael" <mi*****@clift. com.au> wrote
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

Yes. A compiler can implement automatic variables in any way it likes. Some
small embedded systems don't even use a stack but allocate to fixed areas of
memory.
However typically a compiler will adjust the stack frame on function entry
to hold all variables declared in that function, and reset it on function
exit. This means that your block scope array is treated as if it had
function scope. Your own system may be different, but probably not if it is
a major compiler.
Nov 14 '05 #4
"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
"Michael" <mi*****@clift. com.au> wrote
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

Yes. A compiler can implement automatic variables in any way it likes. Some
small embedded systems don't even use a stack but allocate to fixed areas of
memory.


Note that an implementation that doesn't support recursion (and
therefore distinct storage for local variables for each function call)
is not conforming, though it might still be useful.

On the other hand, using a fixed area of memory for a function that's
known not to be called recursively is perfectly legal.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
mi*****@clift.c om.au (Michael) wrote...
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.
As far as the language specification is concerned automatic data will
only be allocated at the point of declaration, and will expire at the
end of the enclosing block scope.
However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};


An implementation can do whatever it likes, so long as it preserves
the semantics of strictly conforming code.

If silently moving the declaration of buffer to the top of the
function block would not change the semantics of your code, then your
compiler can (and likely will) do so in the interests of runtime
efficiency.

But comp.lang.c is not the forum to discus what particular
implementations do under the hood, unless it's to gain an
understanding of C language itself. [Understanding C in terms of
assembler or debugging/profiling tools is not something that clc
encourages, nor should it.]

--
Peter
Nov 14 '05 #6
mi*****@clift.c om.au (Michael) wrote:
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

if(midnightflag ==1)
{
{ unsigned char buffer[40];
};
};

The braces dictate that the name "buffer" is available only
within those braces. However the actual 40 bytes can exist at
any time. The compiler could even allocate them at compile-time
if it determined that the function was never called re-entrantly
(I know of a compiler that does this).
Nov 14 '05 #7
go***********@b urditt.org (Gordon Burditt) wrote in message news:<cl******* *@library2.airn ews.net>...
In the below example, I believe that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.
(1) what stack?

The stack in an MSP430 microcontroller
(2) which stack? The MSP only has one.

Standard C is not required to use a stack.
However the compiler seems to use 40 bytes of the stack throughout the
entire function that this example is cut from. Is this normal?
How did you determine this from the code below, or, for that
matter, using any portable code?


By viewing the assembly code generated by the compiler.
And what difference does it make?
The imagecraft compiler I am using allocates memory for static and
global variables in the lower part of memory, it then uses the stack
for other variables from the top of memory downwards.

I wish to increase the size of a static array as much as possible
without the stack overwriting it. I placed breakpoints in parts of my
program where i had a lot of variables in scope, to see how low the
stack pointer was.

Sorry my question wasn't very clear, what I wanted to know was:

In the code below (whether using a stack or not), should the char
array buffer[] occupy memory for the entire function which this code
is cut from (even though it is only accessible within the braces), OR,
should it only occupy memory within the braces. I would have thought
the latter, but maybe this is not a requirement of standard C.
if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};


Gordon L. Burditt

Nov 14 '05 #8
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote in message news:<cl******* ***@news6.svr.p ol.co.uk>...
"Michael" <mi*****@clift. com.au> wrote
In the below example, I beleive that the char array buffer[40] should
only occupy 40 bytes of the stack within the inner braces.

However the compiler seems to use 40 bytes of the stack througout the
entire function that this example is cut from. Is this normal?

Yes. A compiler can implement automatic variables in any way it likes. Some
small embedded systems don't even use a stack but allocate to fixed areas of
memory.
However typically a compiler will adjust the stack frame on function entry
to hold all variables declared in that function, and reset it on function
exit. This means that your block scope array is treated as if it had
function scope. Your own system may be different, but probably not if it is
a major compiler.


Thanks Malcolm.
Nov 14 '05 #9
Michael wrote:
[snip]

Sorry my question wasn't very clear, what I wanted to know was:

In the code below (whether using a stack or not), should the char
array buffer[] occupy memory for the entire function which this code
is cut from (even though it is only accessible within the braces), OR,
should it only occupy memory within the braces. I would have thought
the latter, but maybe this is not a requirement of standard C. Definitely the latter (see section 6.2.4 of the standard). The former
behaviour is often achieved with the alloca() function.

Robert
if(midnightflag ==1)
{
lcd_clear();
lcd_locate(1,1) ;
lcd_display("Up dating date");
{ unsigned char buffer[40];
daydateyear(buf fer);
senduart2(buffe r);
senduart2("\r\n ");
};
update_date();
midnightflag=0;
};


Gordon L. Burditt

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2048
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since the thread is over a month old, I decided to start a new one with my response. Please see my comments inline.
4
13012
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage reported through task manager peaks between 41-42MB. I've stopped and restarted the MSSQLserver service and checked that the running values are what I set them to be. Does anybody have any ideas as to why the sqlservr.exe would be utilizing more...
4
2591
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on Solaries OS? This means that I use new to allocate memory in one Thread and doesn't use delete to release them.
9
2354
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but not necessary give it back to the OS. It seems that .NET win app will only return memory to the OS when the OS is asking for it. But!!! When the OS is asking for it is usually too late, tons of swapping and slow performance.
22
3484
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from application server, will each connection take the memory 800M (200000 x 4k = 800 M), so the memory took will be 800M times number of connections, or the total memory get from bufferpool will be 800M?
14
20785
by: Alessandro Monopoli | last post by:
Hi all, I'm searching a PORTABLE way to get the available and total physical memory. Something like "getTotalMemory" and it returns the memory installed on my PC in bytes, and "getAvailableMemory" and it returns the available memory in bytes. Do you know is there's a C function, a c++ Object or anything else that compiles in Linux and Windows to get these data?
1
3016
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data structure actually needs once it is loaded in memory. The programs below create a file (z.py) with a data structure in which looks like this -- z.py ---------------------------------------------------- z = {
5
24805
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS (I am new to Windows so not sure). We are currently bouncing the instance to overcome this error. This generally happen at the end of business day only (So maybe memory might be getting used up?). We have already increased the statement heap & ...
1
2047
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after the objects for which that memory was allocated are no longer live in the process. This is only a leak if peak memory goes up again each time you create any new objects. Try repeated allocations of a large dictionary and observe how memory...
5
505
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store pointers of type structure "SAMPLE_TABLE_STRUCT" ( size of this structure is 36 bytes ). I create an instance of structure "SAMPLE_TABLE_STRUCT" using operator "new" and push back into the vector,this is done inside a for loop for
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.