473,406 Members | 2,549 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,406 software developers and data experts.

run-time sized array

Hi all,

I have an array that I don't know the size requirement until run-time.
The way I handle this is:

int* piMyData;

piMyData = (int*)LocalAlloc(LPTR, sizeof(int)*iDataCount); //MS-specific
I also have a 2D char array that I don't know the size requirement until
run-time. Is there a similar method for handling this?
--

Best wishes,
Allen

No SPAM in my email !!


Jul 19 '05 #1
7 6710
On Fri, 22 Aug 2003 23:31:58 GMT, "Allen" <al************@att.SPAM.net> wrote:
Hi all,

I have an array that I don't know the size requirement until run-time.
The way I handle this is:

int* piMyData;

piMyData = (int*)LocalAlloc(LPTR, sizeof(int)*iDataCount); //MS-specific

std::vector<int> v( dataCount );

v[someIndex] = someValue;

I also have a 2D char array that I don't know the size requirement until
run-time. Is there a similar method for handling this?


Use a vector of vectors.

Jul 19 '05 #2
"Allen" <al************@att.SPAM.net> wrote in message
news:OJ**********************@bgtnsc05-news.ops.worldnet.att.net...
| I have an array that I don't know the size requirement until run-time.
| The way I handle this is:
|
| int* piMyData;
|
| piMyData = (int*)LocalAlloc(LPTR, sizeof(int)*iDataCount);
//MS-specific

Remember that you are posting to a "C++" newsgroup, not "C":
piMyData = static_cast<int*>(LocalAlloc(LPTR, sizeof(int)*iDataCount));

| I also have a 2D char array that I don't know the size requirement
until
| run-time. Is there a similar method for handling this?

Do you mean similar in terms of using native win32 (non standard) methods?
That is off topic here. There is a simple way that many novices use to
figure out the total size of any array (though it is frowned upon):

size_t size = sizeof(array[0][0]) * sizeof(array);
Jul 19 '05 #3

"Greg P." <no@spam.sam> wrote in message
news:o1****************@newsread4.news.pas.earthli nk.net...
"Allen" <al************@att.SPAM.net> wrote in message
news:OJ**********************@bgtnsc05-news.ops.worldnet.att.net...
| I have an array that I don't know the size requirement until run-time. | The way I handle this is:
|
| int* piMyData;
|
| piMyData = (int*)LocalAlloc(LPTR, sizeof(int)*iDataCount);
//MS-specific

Remember that you are posting to a "C++" newsgroup, not "C":
piMyData = static_cast<int*>(LocalAlloc(LPTR, sizeof(int)*iDataCount));

| I also have a 2D char array that I don't know the size requirement
until
| run-time. Is there a similar method for handling this?

Do you mean similar in terms of using native win32 (non standard) methods?
That is off topic here. There is a simple way that many novices use to
figure out the total size of any array (though it is frowned upon):

size_t size = sizeof(array[0][0]) * sizeof(array);


Hi Greg,

No, I'm not trying to determine the size. Also, I'm using a very old
compiler that doesn't have vectors and besides, I don't have any experience
using the STL.

I'm looking for a method similar to the first one I gave to create
storage for a 2D array that I don't know the size of until run-time (at
which time, I do).
In the first example, I get iDataCount and create an array at piMyData.
Then, I can:

piMyData[i] = iSomeInt;

I want to get iXCount and iYCount and create a 2D array that I can
access:

pszMyData[x][y] = "a";
--

Best wishes,
Allen

No SPAM in my email !!


Jul 19 '05 #4
In article <gt**********************@bgtnsc05-news.ops.worldnet.att.net>,
Allen <al************@att.SPAM.net> wrote:

I want to get iXCount and iYCount and create a 2D array that I can
access:

pszMyData[x][y] = "a";


If you don't want to use a vector of vectors, then you'll have to use
dynamic memory allocation with 'new'. This is covered in section 16.15 of
the FAQ at <http://www.parashift.com/c++-faq-lite/>.

--
Jon Bell <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 19 '05 #5
> Hi Greg,

No, I'm not trying to determine the size. Also, I'm using a very old
compiler that doesn't have vectors and besides, I don't have any experience using the STL.

I'm looking for a method similar to the first one I gave to create
storage for a 2D array that I don't know the size of until run-time (at
which time, I do).
In the first example, I get iDataCount and create an array at piMyData. Then, I can:

piMyData[i] = iSomeInt;

I want to get iXCount and iYCount and create a 2D array that I can
access:

pszMyData[x][y] = "a";
--


This is in the FAQ.

http://www.parashift.com/c++-faq-lit...tore-mgmt.html

question 16.15. You should be able to translate the use of new to
LocalAlloc, or better still drop LocalAlloc and use new instead. Every C++
compiler ever invented must have new, surely.

john

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 19/08/2003
Jul 19 '05 #6
"Allen" <al************@att.SPAM.net> wrote in message news:<OJ**********************@bgtnsc05-news.ops.worldnet.att.net>...
Hi all,

I have an array that I don't know the size requirement until run-time.
The way I handle this is:

int* piMyData;

piMyData = (int*)LocalAlloc(LPTR, sizeof(int)*iDataCount); //MS-specific

Why not use:

{
int* piMyData;
int size_piMyData = my_array_has_this_many_elements;
Jul 19 '05 #7
Allen wrote:

No, I'm not trying to determine the size. Also, I'm using a very old
compiler that doesn't have vectors
Sounds like a good time to get a new compiler.
and besides, I don't have any experience
using the STL.


Sounds like a good time to learn.

Ask in a C++ group, get a C++ answer. Use vector. It's infinitely
superior to anything you are likely to come up with.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #8

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

Similar topics

4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
19
by: Bryan | last post by:
How can i run a bit of code straight from the IDE? Right now i make a temporary button and put the code behind that, then i run debug mode and click on the button. Is there a way to highlight...
9
by: Brett Wesoloski | last post by:
I am new to VS2005. I changed my program.cs file to be a different form I am working on. But when I go to run the application it still brings up the form that was originally declared as new. ...
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.