• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 22:10
CET 04:10
KST 12:10
  • 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
HomeStory Cup 28 - Info & Preview10Rongyi Cup S3 - Preview & Info3herO wins SC2 All-Star Invitational14SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8
Community News
Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win3Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)38
StarCraft 2
General
HomeStory Cup 28 - Info & Preview StarCraft 2 Not at the Esports World Cup 2026 Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win Oliveira Would Have Returned If EWC Continued herO wins SC2 All-Star Invitational
Tourneys
HomeStory Cup 28 KSL Week 85 $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) OSC Season 13 World Championship $70 Prize Pool Ladder Legends Academy Weekly Open!
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 510 Safety Violation Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained
Brood War
General
Bleak Future After Failed ProGaming Career [ASL21] Potential Map Candidates BW General Discussion Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 Azhi's Colosseum - Season 2 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Path of Exile Mobile Legends: Bang Bang Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Hager werken embalming powder+27 81 711 1572
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
Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1965 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
Hyrule19191 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
Hyrule19191 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
Korean StarCraft League
03:00
Week 85
davetesta24
HKG_Chickenman17
Liquipedia
The PiG Daily
21:40
Best Games of SC
Reynor vs Krystianer
herO vs Rogue
ByuN vs TriGGeR
Maru vs Solar
PiGStarcraft565
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft565
ProTech263
RuFF_SC2 198
NeuroSwarm 106
Ketroc 38
SortOf 4
StarCraft: Brood War
Shuttle 329
NaDa 82
Icarus 6
Dota 2
monkeys_forever337
LuMiX1
League of Legends
JimRising 590
C9.Mang0436
Counter-Strike
taco 561
adren_tv59
minikerr21
Other Games
tarik_tv15001
summit1g7229
gofns5285
ViBE144
KnowMe72
ZombieGrub28
Organizations
Other Games
gamesdonequick1098
BasetradeTV63
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• HeavenSC 32
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21358
League of Legends
• Doublelift5146
Upcoming Events
HomeStory Cup
8h 50m
Replay Cast
20h 50m
HomeStory Cup
1d 9h
Replay Cast
1d 20h
Replay Cast
2 days
Wardi Open
3 days
WardiTV Invitational
4 days
The PondCast
5 days
WardiTV Invitational
5 days
Liquipedia Results

Completed

Escore Tournament S1: W6
OSC Championship Season 13
Underdog Cup #3

Ongoing

CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Acropolis #4 - TS4
Rongyi Cup S3
HSC XXVIII
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W7
Escore Tournament S1: W8
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
LiuLi Cup: 2025 Grand Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
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 © 2026 TLnet. All Rights Reserved.