473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

char array memory collection

1
I'm creating a char array in the following way, and don't know whether it is being collected or not. I know I have a memory leak somewhere in my code ("ps wwvg | grep myapplication" shows memory usage) , but I'm not sure if it's being caused by the following:


Expand|Select|Wrap|Line Numbers
  1.  
  2. void example()
  3. {
  4. char array[50000]="";
  5. }
  6.  
That's basically it. Normally I would do something like

Expand|Select|Wrap|Line Numbers
  1. char * array = new char[5000];
in which case I would know to delete it, but I can't find any info on the first way of creating/deleting an array.
Aug 9 '07 #1
2 2801
JosAH
11,448 Expert 8TB
I'm creating a char array in the following way, and don't know whether it is being collected or not. I know I have a memory leak somewhere in my code ("ps wwvg | grep myapplication" shows memory usage) , but I'm not sure if it's being caused by the following:


Expand|Select|Wrap|Line Numbers
  1.  
  2. void example()
  3. {
  4. char array[50000]="";
  5. }
  6.  
That's basically it. Normally I would do something like

Expand|Select|Wrap|Line Numbers
  1. char * array = new char[5000];
in which case I would know to delete it, but I can't find any info on the first way of creating/deleting an array.
In your first example the array is a so called 'automatic' variable, i.e. it resides on
the stack and is 'automatically' ripped from existence when the function returns.

kind regards,

Jos
Aug 9 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Also, be careful of large stack memory usage. Some systems limit stack to as little as 4K without negotiating with a SysAdmin for more.

Prefer the heap to the stack.
Aug 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: mike79 | last post by:
Hello all, I am a newbie to C, so please bear with me :) I need to create an array in a function (a local variable) with size of 1MB. Since local variables get stored on the stack, at...
3
by: sieg1974 | last post by:
Hi, I have made this simple program to understand char ** pointers, but I still having many questions. int main() { char ** testPointerPointerChar = 0; char * A = "string01";
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
19
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0...
5
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
11
by: rayreeves | last post by:
How do I declare an array of references to the elements of an array of values? Ray
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.