TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Geo
from: Paul Ranson
date: 2004-11-23 11:26:36
subject: Re: C++ for beginners?

From: "Paul Ranson" 

It doesn't do anything. My loglines is equivalent to yours except that the
memory was allocated from the heap at the time of the 'new' call.

'new' returns a pointer, so it is necessary to declare 'loglines' as a
pointer. This is implicit when you declare a fixed size array, and needs to
be explicit in this case. Usage is exactly the same as for your
declaration.

C/C++ pointers can be tricky to explain, and I don't know where you've got
to, so I'm not even going to try... Read it as 'star loglines is an array
of 256 char' so loglines[0] is an array of 256 char, and we allocated space
for 4096 lines, so loglines[4095] is the last array of 256 char.

Paul

"Geo"  wrote in message
news:41a2ab5c$1{at}w3.nls.net...
> what does the *loglines part of this do?
>
> Geo.
>
> "Paul Ranson"  wrote in message
> news:41a289a5$1{at}w3.nls.net...
>> I'm guessing you allocated this as an 'automatic', IOW on the stack. Your
>> exe probably has a maximum stack size of 1MB. So bang.
>>
>> Simplest would be to make your stack bigger, this is usually a linker
>> option.
>>
>> Or allocate on the heap, this is the proper choice but you are going to
>> enter a really dark cavern if you go this way.
>>
>> Try,
>>
>> char (*loglines)[256] = new char [4096][256] ;
>>
>> use as you would your declaration and at the end it's polite to call,
>>
>> delete [] loglines ;
>>
>> You can vary the 4096 at run time.
>>
>> I need to say that this is not the right approach, you should create a
>> std::vector of std::string. But I guess this isn't covered yet. Have fun
>> debugging...
>>
>> Paul

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.