• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:55
CET 14:55
KST 22:55
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners10Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
StarCraft, SC2, HotS, WC3, Returning to Blizzcon!33$5,000+ WardiTV 2025 Championship6[BSL21] RO32 Group Stage4Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win10
StarCraft 2
General
Mech is the composition that needs teleportation t TL.net Map Contest #21: Winners Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win RotterdaM "Serral is the GOAT, and it's not close" 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
Constellation Cup - Main Event - Stellar Fest $5,000+ WardiTV 2025 Championship Sparkling Tuna Cup - Weekly Open Tournament Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
[ASL20] Ask the mapmakers — Drop your questions BW General Discussion [BSL21] RO32 Group Stage BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review
Tourneys
[Megathread] Daily Proleagues [ASL20] Grand Finals [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile Should offensive tower rushing be viable in RTS games? Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1412 users

The Big Programming Thread - Page 133

Forum Index > General Forum
Post a Reply
Prev 1 131 132 133 134 135 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Millitron
Profile Blog Joined August 2010
United States2611 Posts
April 12 2012 00:02 GMT
#2641
On April 12 2012 07:37 MisterD wrote:
Show nested quote +
On April 12 2012 07:27 ObliviousNA wrote:
On April 12 2012 06:36 Millitron wrote:
On April 12 2012 01:06 phar wrote:
@ Above w/ the C++ & Java:

Depending on the scope of your need to communicate between C++ and Java, it may be worth investing some time into looking at JNI Bridge. Despite the fact that it may make you want to pull your hair out, if you are doing a lot of integration between the languages it'll potentially save you a lot of time.

If your need is pretty simple though (e.g. is limited to literally just stuffing one chunk of data at one single point in java to one single point in C++), then JNI Bridge will be overkill.

I just need to start a C++ program and pass it a parameter from within a Java program. I may also want to get a little output from the C++ program, but I can probably do without it.

The Java program is a UI to enable easier access to a much larger C++ program. Right now, the C++ program is just run from command line, but the hope is that eventually non-CS people will be able to use it.


Ok, so I recommend redoing this with an executable that you know works. Try starting up IE or something basic, and stepping through your code. I'm unfamiliar with Java, but I've done this a lot with System.Diagnostics in .Net (Process and ProcessStartInfo classes) and I've been able to capture stdOUT and stdERR reliably.

This may be blatantly wrong (again unfamiliar with java), but doesnt your EXE spawn its own thread and execute when you call process.start() ? This means you're assigning output / input streams after the program has run. Just a guess.

Edit: Because of the class names 'Process' and 'ProcessBuilder' I'm assuming it functions similar to the .NET classes.


The process does start in a separate thread, hence you are assigning input and output streams _while_ the other process is running, not after. But any output occurring is buffered until you actually read it, so you don't miss anything. In fact, some programs you run this way will block because they are either waiting for input or because output buffers just run full and so their print to stdout gets blocked until you start reading from these streams.


I've just been trying it on Hello World right now, and it definitely works, when run on its own. Its when I try to call it from my Java program that I run into trouble.

What bothers me, is that it starts in another thread. Why doesn't the C++ program start its own runtime environment? Why does it get a thread in the Java program?
Who called in the fleet?
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
April 12 2012 08:00 GMT
#2642
On April 12 2012 09:02 Millitron wrote:
Show nested quote +
On April 12 2012 07:37 MisterD wrote:
On April 12 2012 07:27 ObliviousNA wrote:
On April 12 2012 06:36 Millitron wrote:
On April 12 2012 01:06 phar wrote:
@ Above w/ the C++ & Java:

Depending on the scope of your need to communicate between C++ and Java, it may be worth investing some time into looking at JNI Bridge. Despite the fact that it may make you want to pull your hair out, if you are doing a lot of integration between the languages it'll potentially save you a lot of time.

If your need is pretty simple though (e.g. is limited to literally just stuffing one chunk of data at one single point in java to one single point in C++), then JNI Bridge will be overkill.

I just need to start a C++ program and pass it a parameter from within a Java program. I may also want to get a little output from the C++ program, but I can probably do without it.

The Java program is a UI to enable easier access to a much larger C++ program. Right now, the C++ program is just run from command line, but the hope is that eventually non-CS people will be able to use it.


Ok, so I recommend redoing this with an executable that you know works. Try starting up IE or something basic, and stepping through your code. I'm unfamiliar with Java, but I've done this a lot with System.Diagnostics in .Net (Process and ProcessStartInfo classes) and I've been able to capture stdOUT and stdERR reliably.

This may be blatantly wrong (again unfamiliar with java), but doesnt your EXE spawn its own thread and execute when you call process.start() ? This means you're assigning output / input streams after the program has run. Just a guess.

Edit: Because of the class names 'Process' and 'ProcessBuilder' I'm assuming it functions similar to the .NET classes.


The process does start in a separate thread, hence you are assigning input and output streams _while_ the other process is running, not after. But any output occurring is buffered until you actually read it, so you don't miss anything. In fact, some programs you run this way will block because they are either waiting for input or because output buffers just run full and so their print to stdout gets blocked until you start reading from these streams.


I've just been trying it on Hello World right now, and it definitely works, when run on its own. Its when I try to call it from my Java program that I run into trouble.

What bothers me, is that it starts in another thread. Why doesn't the C++ program start its own runtime environment? Why does it get a thread in the Java program?


I don't know if it gets an actual java thread or if the JVM just forks off a regular operating system thread to run it in, why does that make a difference? you don't see it anyways.
Gold isn't everything in life... you need wood, too!
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
April 12 2012 08:29 GMT
#2643
On April 12 2012 07:02 mazerr wrote:
Hi TeamLiquid! Long-time (2yr) lurker here, and I finally decided to post, because I need some help! Lengthy read below, but if any of you programming wizards could give some advice I'd appreciate it! I cross-posted this on reddit careeradvice but don't know if I'll get any responses there.

First, a little about my background:

I'm a 23 year old currently living at home. I was a very 'gifted' person when I was younger, ie got As in school w/o effort, played violin and ended up winning a nation-wide HS competition and performed in Carnegie Hall, won local Math competitions, etc, all with very minimal effort. Because of this I developed a superiority complex and became very apathetic regarding what I wanted to do, as I was good at a number of things and a lot of people were pushing me to do 'their' thing. I didn't know what I wanted to do. So I promptly got into a decent engineering school (Rose-Hulman) spent all my time playing WoW, and bombed out. This shattered my superiority complex and triggered depression, which deteriorated over the years to the point where I was living at home, morbidly obese, smoking, and pissing in bottles and letting food rot in my room while I played video games.

I have step-by-step overcome this, and am now trying to get my life back on track, but I need to move out, my parents can simply no longer support me (nor do I wish them to). I REALLY desperately want to begin a career as a programmer. Out of all of the things I've done, I like it the most by far (barring music which I love too personally to want it as a job). I've dabbled in a number of different languages (Python, AS3 (lol), C, Java, and Obj-C) and I really enjoy them all equally, I enjoy just the process of coding and pick it up relatively quickly as far as I can judge (ie finished a semester's course-work of a few of them in a month).

I need to move out within a few months, but I have enough money to support myself for around a year. What I would LIKE to be able to do is to pick a language and become proficient enough at it within a year to support myself (around 18k USD a year where I live) by either freelance, web-design, independent flash-game development, anything really. I realize without a degree getting a steady job would near impossible. So what I would like to know (apologies for the length of the post) is is this possible, or is it just a pipe-dream? Please do keep in mind I can learn things extremely quickly, but I realize there's a significant portion of it that can't be brute-forced. And if it is possible, what language and career should I focus on?

The alternative is for me to find a regular minimum-wage job and try to go to school and learn programming on the side, but in this economy I'd be working most of my time and likely wouldn't have my degree until I'm close to 30, and the thought of just starting my career at thirty makes me have a sick feeling in my stomach :/

TL;DR: Can someone who is able to learn things relatively quickly learn programming to a degree that is able to support them, and if so, what language and/or area of programming should they focus on?

Thank you for your time!


Somehow reading this post made me angry...

Programming is no "get rich fast" scheme, it requires a lot of dedication, hard work and _experience_. Yes, you can become a web designer by copy-pasting a lot of stuff together, a child could do that. However, you will need a lot more time for everything than an experienced programmer, which means in the end you will have to provide your services either for more money than your competitors or work around minimum wage (or below) anyways.

Get a minimum wage job and start to develop websites or flash stuff on the side, get experience, get references and _then_ you might make it. Otherwise you will be just another of those webdesigners that live by the scraps of what the bigger fish don't want to do.

You might also want to apply at professional companies anyways. You can get jobs without a degree if you can prove that you really know how to program. Tell them you are willing to do an internship for free for a month to prove your skills... just make sure you actually have the skills.

If you really want to go freelance, there are 2 major groups these days:
1. Web stuff: HTML5, a lot of JavaScript, easy to learn, a lot of competition, comparatively easy to get jobs but low win margins these days. The time of the bubble is long gone.
2. Smartphone apps: HTML5 and JS with a converter to native code is ok for a lot of small applications but usually you either need Java for Android or a Mac and Objective-C for iphone development. Harder to learn, less competition, harder to find jobs but the win margins can be significantly higher than for Web stuff.
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
April 12 2012 14:21 GMT
#2644
A portfolio is more important than a degree in the programming world. Make stuff, then on interviews you can say "look at these things I've made" and then you get a job.
Liquipediaasante sana squash banana
phar
Profile Joined August 2011
United States1080 Posts
April 12 2012 17:27 GMT
#2645
On April 12 2012 17:29 Morfildur wrote:
Programming is no "get rich fast" scheme, it requires a lot of dedication, hard work and _experience_. Yes, you can become a web designer by copy-pasting a lot of stuff together, a child could do that. However, you will need a lot more time for everything than an experienced programmer, which means in the end you will have to provide your services either for more money than your competitors or work around minimum wage (or below) anyways.

This 100x

Study up:

http://learnpythonthehardway.org/book/
http://www.khanacademy.org/#computer-science
Who after all is today speaking about the destruction of the Armenians?
Millitron
Profile Blog Joined August 2010
United States2611 Posts
April 12 2012 21:19 GMT
#2646
On April 12 2012 17:00 MisterD wrote:
Show nested quote +
On April 12 2012 09:02 Millitron wrote:
On April 12 2012 07:37 MisterD wrote:
On April 12 2012 07:27 ObliviousNA wrote:
On April 12 2012 06:36 Millitron wrote:
On April 12 2012 01:06 phar wrote:
@ Above w/ the C++ & Java:

Depending on the scope of your need to communicate between C++ and Java, it may be worth investing some time into looking at JNI Bridge. Despite the fact that it may make you want to pull your hair out, if you are doing a lot of integration between the languages it'll potentially save you a lot of time.

If your need is pretty simple though (e.g. is limited to literally just stuffing one chunk of data at one single point in java to one single point in C++), then JNI Bridge will be overkill.

I just need to start a C++ program and pass it a parameter from within a Java program. I may also want to get a little output from the C++ program, but I can probably do without it.

The Java program is a UI to enable easier access to a much larger C++ program. Right now, the C++ program is just run from command line, but the hope is that eventually non-CS people will be able to use it.


Ok, so I recommend redoing this with an executable that you know works. Try starting up IE or something basic, and stepping through your code. I'm unfamiliar with Java, but I've done this a lot with System.Diagnostics in .Net (Process and ProcessStartInfo classes) and I've been able to capture stdOUT and stdERR reliably.

This may be blatantly wrong (again unfamiliar with java), but doesnt your EXE spawn its own thread and execute when you call process.start() ? This means you're assigning output / input streams after the program has run. Just a guess.

Edit: Because of the class names 'Process' and 'ProcessBuilder' I'm assuming it functions similar to the .NET classes.


The process does start in a separate thread, hence you are assigning input and output streams _while_ the other process is running, not after. But any output occurring is buffered until you actually read it, so you don't miss anything. In fact, some programs you run this way will block because they are either waiting for input or because output buffers just run full and so their print to stdout gets blocked until you start reading from these streams.


I've just been trying it on Hello World right now, and it definitely works, when run on its own. Its when I try to call it from my Java program that I run into trouble.

What bothers me, is that it starts in another thread. Why doesn't the C++ program start its own runtime environment? Why does it get a thread in the Java program?


I don't know if it gets an actual java thread or if the JVM just forks off a regular operating system thread to run it in, why does that make a difference? you don't see it anyways.

I think it does make a difference though. I think why I can't get any output is that it does start a Java thread, and then control never goes back to the original thread, because the C++ one never ends.
Who called in the fleet?
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
April 12 2012 23:17 GMT
#2647
no, the process start returns control flow immediately. if you want to wait for the process to end, you explicitly have to call process.waitFor();

try the following: make a very simple program that does nothing but start the c++ program and then System.out.println("hello"); and execute it. You will see the "hello" immediately after the c++ program has started.
Gold isn't everything in life... you need wood, too!
DaPyro
Profile Blog Joined January 2012
Serbia131 Posts
Last Edited: 2012-04-15 10:10:21
April 15 2012 10:08 GMT
#2648
Can someone help me with a php function please

Im creating a function to create 3 drop down lists, the lists are in two arrays either
1.
$colors = array('White' =>'white','Black'=> 'black', 'Red'=>'red','Green'=>'green','Blue'=>'blue','Yellow'=>'yellow','Orange'=>'orange');

or
$fancy_colors = array('cyan' => '33CCFF', 'gold' => 'F5B800', 'pink' => 'FF33CC', 'lime' => 'CCFF33');


my 3 calls are:

selectBox($colors, "Text Color:", "textColor");
selectBox( $colors, "Background Color:", "backColor");
selectBox( $fancy_colors, "Box Color:", "boxColor");


my function:

function selectBox( $list, $title, $name)
{
echo "<p>""$title""<select name=""$name"">";
foreach ($list as $key => $value)
echo "<option value=" . "$value" . ">" . "$key" ." </option>";
echo "</select></p>";
return $value;
}


can anyone help me with why it wont work?
Drone so hard motherfuckers wanna fine me. Whats 50k minerals to a nigga like me? can you please remind me
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
Last Edited: 2012-04-15 11:25:01
April 15 2012 11:22 GMT
#2649
your echo lines with these """""" look rather confusing, i'd assume there's some error in there. I remember from when i wrote some php a few years back, i always put {$variable} in {} because it'd screw up regularly otherwise, maybe try that. but a more readable way to write these things would probably be, to write all html as ' strings and put the $ values in manually without the "-string magic:

echo '<p>'.$title.'<select name="'.$name.'">";


it's not as obvious here but it helps a lot when not using strings, e.g. you can write

echo '<p style="color:red">';

without having to double quote anything etc.


for more help without us having to guess what happens, post some output that gets created. "doesn't work" gives absolutely no indication as to what might be wrong, and a lot of people don't have a php execution environment around and probably won't set one up to test your code themselves to find this information. If it gives an error, post it. If it gives screwed up output, post that.
Gold isn't everything in life... you need wood, too!
tofucake
Profile Blog Joined October 2009
Hyrule19151 Posts
April 15 2012 12:07 GMT
#2650
echo "

$title

Aresien
Profile Blog Joined February 2009
United Kingdom305 Posts
April 19 2012 20:54 GMT
#2651
Hey guys, I was hoping I could get a little bit of help with a project I have due soon.

Basically i've been asked to create a top-down shooter game using Python (pygame). The interesting part of the project though is to create power-ups/weapons that are created in game (not pre-defined). I'm now at the stage where I have the base game which features all the other stuff required, but I still have to implement the power-ups. I'm super rusty with Python right now (not used it for a year or so), does anyone have any suggestions for going about this? Just looking for general ideas, any help would be appriciated!
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
April 19 2012 21:38 GMT
#2652
On April 12 2012 07:02 mazerr wrote:
Hi TeamLiquid! Long-time (2yr) lurker here, and I finally decided to post, because I need some help! Lengthy read below, but if any of you programming wizards could give some advice I'd appreciate it! I cross-posted this on reddit careeradvice but don't know if I'll get any responses there.

First, a little about my background:

I'm a 23 year old currently living at home. I was a very 'gifted' person when I was younger, ie got As in school w/o effort, played violin and ended up winning a nation-wide HS competition and performed in Carnegie Hall, won local Math competitions, etc, all with very minimal effort. Because of this I developed a superiority complex and became very apathetic regarding what I wanted to do, as I was good at a number of things and a lot of people were pushing me to do 'their' thing. I didn't know what I wanted to do. So I promptly got into a decent engineering school (Rose-Hulman) spent all my time playing WoW, and bombed out. This shattered my superiority complex and triggered depression, which deteriorated over the years to the point where I was living at home, morbidly obese, smoking, and pissing in bottles and letting food rot in my room while I played video games.

I have step-by-step overcome this, and am now trying to get my life back on track, but I need to move out, my parents can simply no longer support me (nor do I wish them to). I REALLY desperately want to begin a career as a programmer. Out of all of the things I've done, I like it the most by far (barring music which I love too personally to want it as a job). I've dabbled in a number of different languages (Python, AS3 (lol), C, Java, and Obj-C) and I really enjoy them all equally, I enjoy just the process of coding and pick it up relatively quickly as far as I can judge (ie finished a semester's course-work of a few of them in a month).

I need to move out within a few months, but I have enough money to support myself for around a year. What I would LIKE to be able to do is to pick a language and become proficient enough at it within a year to support myself (around 18k USD a year where I live) by either freelance, web-design, independent flash-game development, anything really. I realize without a degree getting a steady job would near impossible. So what I would like to know (apologies for the length of the post) is is this possible, or is it just a pipe-dream? Please do keep in mind I can learn things extremely quickly, but I realize there's a significant portion of it that can't be brute-forced. And if it is possible, what language and career should I focus on?

The alternative is for me to find a regular minimum-wage job and try to go to school and learn programming on the side, but in this economy I'd be working most of my time and likely wouldn't have my degree until I'm close to 30, and the thought of just starting my career at thirty makes me have a sick feeling in my stomach :/

TL;DR: Can someone who is able to learn things relatively quickly learn programming to a degree that is able to support them, and if so, what language and/or area of programming should they focus on?

Thank you for your time!


Hi Mazerr! I am an alum from Rose-hulman, and Id love to offer some advice for how to learn programming. You should not feel bad about bombing out of such a school. Its learning style is not for everyone, and I barely survived my way through it. What others have said about picking up programming is definitely true. It takes years of experience before you can turn it into a living.

Dont be discouraged by that! Most people settle into their careers later in life. Getting out of high school, doing well in college, then starting at an entry level position is not the norm.

First bit of advice)
I suggest you find a local hackerspace (google is your friend), and get involved. Those are the local DIY/startup guys, and they love bright self driven people. If you do end up having a natural talent and drive, youll find yourself being picked up before you can even program.

Next bit)
Programming is a big word that means a whole lot of nothing. You could be an embedded programmer, a web programmer (back or front end), a high speed programmer, automotive programmer, open source, high reliability, secure, game designer, etc.. The list goes on and on. You're going to end up pidgeonholing yourself at some point, probably after your first 3 years (it takes about that long to get a handle of basic algorithms and concepts). Focus not on the specific part, but the general feel of what it takes to program. You don't need a degree for that, and good employers will know this, and invest their own money to train you to be good at the specific thing they need you for. Its easier and cheaper to find someone trainable and teach them than it is to pay more for the right fit.

Finally)
Anything is possible, and you really can live off of <20kUSD a year anywhere in the world. You wont get the 20k in your first year learnign to program, though. There is a TON of competition, so focus on getting somewhere EVENTUALLY, not just right that moment.

Any sufficiently advanced technology is indistinguishable from magic
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
April 19 2012 22:51 GMT
#2653
On April 20 2012 05:54 Aresien wrote:
Hey guys, I was hoping I could get a little bit of help with a project I have due soon.

Basically i've been asked to create a top-down shooter game using Python (pygame). The interesting part of the project though is to create power-ups/weapons that are created in game (not pre-defined). I'm now at the stage where I have the base game which features all the other stuff required, but I still have to implement the power-ups. I'm super rusty with Python right now (not used it for a year or so), does anyone have any suggestions for going about this? Just looking for general ideas, any help would be appriciated!

You can create a class for your powerup. The class can have data members for the x and y coordinates. I haven't used Pygame for a couple years so I don't remember how images are stored, but I'm sure you can figure out how to get the image onto the powerup if you've completed those other things. Then you can have a method for the functionality of the powerup, and call this method when the player is detected as in collision with the powerup.

If you want advice on how to place the powerups in your levels, there's a lot of ways to do that. The easiest to get set up and working would just be a function that places the powerup within the level at a specified coordinate.
snively
Profile Blog Joined August 2011
United States1159 Posts
April 23 2012 21:50 GMT
#2654
i have some questions. first of all, let me say i suck at programming, so my questions might be wrongly worded or just plain stupid. or both.

now, lets say i am using c++, and i declare a pointer to an integer, and i intend to use it as a dynamically-sized array.
as far as i know, the computer stores bits sequentially, and variables are just chunks of space in memory, in a line.
how does the computer know where to save room for the array? if i declare another integer, how does the computer know where to put it so that it doesnt block the space for the dynamic array? for that matter, does the memory for each part of the array have to next to each other at all? if not, how does the computer know which parts of memory are part of the array and which aren't?

TLDR: how does the computer allocate memory for dynamically-sized arrays?
My religion is Starcraft
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
April 23 2012 23:23 GMT
#2655
it doesn't, you have to do that yourself with malloc / calloc / free.
Gold isn't everything in life... you need wood, too!
Glowbox
Profile Joined June 2010
Netherlands330 Posts
April 23 2012 23:35 GMT
#2656
On April 24 2012 08:23 MisterD wrote:
it doesn't, you have to do that yourself with malloc / calloc / free.


He mentions C++, so why suggest the C-way of allocating? Instead, use new/delete; http://en.wikipedia.org/wiki/New_(C++)
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
April 23 2012 23:37 GMT
#2657
On April 24 2012 08:35 Glowbox wrote:
Show nested quote +
On April 24 2012 08:23 MisterD wrote:
it doesn't, you have to do that yourself with malloc / calloc / free.


He mentions C++, so why suggest the C-way of allocating? Instead, use new/delete; http://en.wikipedia.org/wiki/New_(C++)


oops ^^ haven't used anything c-like in ages ^^ actually never really learned c++, just used it for a bunch of things without knowing what i was doing x.X but well, worked out and doesn't really hurt for study tasks :D
Gold isn't everything in life... you need wood, too!
RoTaNiMoD
Profile Blog Joined January 2004
United States558 Posts
April 23 2012 23:43 GMT
#2658
snively:

When you declare variables without pointers in c++, they are indeed analogous to being "chunks of space in memory, in a line". These variables are stored on the stack. However, dynamic arrays, allocated with the new keyword, are stored in the heap. The heap can be viewed as a vast chunk of available memory, whereas the stack is comparatively limited. Compilers handle the details of heap storage differently, but when you declare an array of 120 items, the metadata of that memory is stored somewhere. The new keyword returns a pointer to the start of the array, but the compiler maintains information about how many elements that array contains, such that when you delete[], everything ends up fine and dandy.

For more information, google/wiki stack vs heap memory.
RoTaNiMoD
Profile Blog Joined January 2004
United States558 Posts
Last Edited: 2012-04-23 23:56:49
April 23 2012 23:55 GMT
#2659
DaPyro:

Assuming that double double-quotes is a way of escaping a single double-quote, your code seems to be fine. Very confusing to look at, but functionally OK. We're gonna need a little more description of what the problem is.

Also, please for the love of God, either A) encase your strings in single quotes so you can use double quotes normally, and use the dot operator to concatenate your php variables, or B) keep with the double quote enclosure but use single-quotes for the HTML. I prefer option A personally, but they each have their merits.

Edit: I think I spoke too soon. I imagine you are expecting some sort of functionality to result from your line of "return $value;". Whatever functionality that is, I'm not even sure, but it's not going to work how you have it set up. What is your goal with the presented code?
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
April 24 2012 09:27 GMT
#2660
On April 24 2012 08:55 RoTaNiMoD wrote:
Edit: I think I spoke too soon. I imagine you are expecting some sort of functionality to result from your line of "return $value;". Whatever functionality that is, I'm not even sure, but it's not going to work how you have it set up. What is your goal with the presented code?


well yes, return $value is stupid there because $value isn't bound to a value outside of the foreach loop. But since he's using echo, the code should be printed out anyways. It might however not be in the right position on the site, search the generated html source for the tags that this piece of code writes to find that out.
Gold isn't everything in life... you need wood, too!
Prev 1 131 132 133 134 135 1032 Next
Please log in or register to reply.
Live Events Refresh
CranKy Ducklings
10:00
Sea Duckling Open #140
CranKy Ducklings84
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 198
Railgan 42
Creator 14
StarCraft: Brood War
Sea 6694
Horang2 4040
GuemChi 1668
Jaedong 862
actioN 292
Mini 259
BeSt 247
Killer 230
Soma 220
EffOrt 210
[ Show more ]
Rush 169
Mind 92
Hyun 87
Bonyth 72
ToSsGirL 69
Backho 61
sas.Sziky 33
JYJ28
PianO 27
zelot 24
Aegong 14
soO 12
Terrorterran 10
Sacsri 9
sorry 9
HiyA 8
Dota 2
Gorgc6041
singsing2292
qojqva1772
Dendi596
XcaliburYe214
BananaSlamJamma90
Heroes of the Storm
Khaldor209
Other Games
B2W.Neo1194
Sick244
Lowko237
Fuzer 197
Hui .121
XaKoH 81
nookyyy 54
MindelVK19
Organizations
StarCraft 2
WardiTV622
Counter-Strike
PGL242
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 67
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2050
League of Legends
• Stunt689
• HappyZerGling113
Upcoming Events
IPSL
4h 5m
dxtr13 vs OldBoy
Napoleon vs Doodle
LAN Event
4h 5m
Lambo vs Clem
Scarlett vs TriGGeR
ByuN vs TBD
Zoun vs TBD
BSL 21
6h 5m
Gosudark vs Kyrie
Gypsy vs OyAji
UltrA vs Radley
Dandy vs Ptak
Replay Cast
9h 5m
Sparkling Tuna Cup
20h 5m
WardiTV Korean Royale
22h 5m
LAN Event
1d 1h
IPSL
1d 4h
JDConan vs WIZARD
WolFix vs Cross
BSL 21
1d 6h
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
1d 19h
[ Show More ]
Wardi Open
1d 22h
WardiTV Korean Royale
2 days
Replay Cast
3 days
Kung Fu Cup
3 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
4 days
The PondCast
4 days
RSL Revival
4 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
4 days
WardiTV Korean Royale
4 days
RSL Revival
5 days
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
5 days
CranKy Ducklings
6 days
RSL Revival
6 days
herO vs Gerald
ByuN vs SHIN
Kung Fu Cup
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
Stellar Fest: Constellation Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.