• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:20
CET 09:20
KST 17:20
  • 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
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (October 19-25): Clem triples first in 5.0.175Evil Geniuses - shutting down21ISSL (IntoTheTV x SOOP SC2 League): Premier7Weekly Cups (October 12-18): 5.0.17 era begins1[$1250] International ShieldBattery League99
StarCraft 2
General
Behind the Blue - Team Liquid History Book No more SC2 streamers on team liquid? 5.0.17 Patch Notes - October 7, 2026 Evil Geniuses - shutting down SC2 Power Rank: epic29
Tourneys
ISSL (IntoTheTV x SOOP SC2 League): Premier Stellar Fest TWO the Moon (Dec 16-20) Sparkling Tuna Cup - Weekly Open Tournament RSL goes to London! 2026 Offline Finals Nov 21-22 RSL 2026 Offline Finals LCQ Sign-Ups
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[D] the control group Simple Questions/Answers [G] How to playtest arcade maps [A] Nemrods 1/4 players
External Content
Mutation # 550 Graveyard Shift The PondCast: SC2 News & Results Mutation # 549 Endless Sparkles Mutation # 548 Shining Bright
Brood War
General
Top Players of October 2026 (EBPD Rankings) Rollback Netcode in Brood War Mathematicians needed to calc "Low Econ Epicness" BW General Discussion [Megathread] Daily Funny Videos
Tourneys
2v2v2v2 Tournament Stage 1: Community Poll [Megathread] Daily Proleagues [IPSL] IPSL Winter 26-27 Ro24 is HERE! [$1250] International ShieldBattery League
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Deus Ex 3!? Stormgate/Frost Giant Megathread Nintendo Switch Thread Mobile Legends: Bang Bang Armies of Exigo - YesYes?
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread The Chess Thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread
Fan Clubs
Reynor Fan Club The Flash Fan Club Serral Fan Club
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
Why I built Repalyzer (1.1.…
BlueStar
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 11240 users

The Big Programming Thread - Page 473

Forum Index > General Forum
Post a Reply
Prev 1 471 472 473 474 475 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.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2014-05-01 16:41:31
May 01 2014 16:15 GMT
#9441
--- Nuked ---
tofucake
Profile Blog Joined October 2009
Hyrule19266 Posts
May 01 2014 16:27 GMT
#9442
MinGW is also run through msys though, which is the whole unix environment thingy. Cygwin compiles against Cygwin.dll and can cause some issues if other versions of it are present on the target system. MinGW compiles into the program so that doesn't happen, but it's more complicated.
Liquipediaasante sana squash banana
bangsholt
Profile Joined June 2011
Denmark138 Posts
May 01 2014 17:43 GMT
#9443
To the UML discussion, let's dive into the two I've used the most.

Sequence diagrams:
This is very useful, when you're communicating with other services - then you can basically draw what happens when and why it happens. Alternative is to go to the source code and try to figure out what is going it - that's of course possible as well, but I would think it will take at least 3-4 times the time that it takes to look at the sequence diagram.

It's also good for when you are designing - if your interaction between whatever two things you are drawing looks awkward... It's probably because it is, and you should try to redesign it into something that's prettier and easier to understand.

Class diagram:

A very nice and simple way to get an overview of a whole system, but where it really shines in my opinion, is when you are designing your systems - because you do design before you code, RIGHT?

This makes it easy to whip up a design which you can then discuss with your fellow coders or engineers or whoever your team consists of.

What happens if you have 20 classes? You make two diagrams or more.

And added to this, most of the time the UML diagrams will always be slightly outdated in comparison to what is happening in the code, but you should strive to keep all your documentation to a high level and updated - it will make your life easier when you get back to something you wrote 5 months ago, and don't remember how to use.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-05-01 18:46:16
May 01 2014 18:42 GMT
#9444
On May 02 2014 01:27 tofucake wrote:
MinGW is also run through msys though, which is the whole unix environment thingy. Cygwin compiles against Cygwin.dll and can cause some issues if other versions of it are present on the target system. MinGW compiles into the program so that doesn't happen, but it's more complicated.


+1 for MinGW for your C++ compiler on windows. Alternatively, you can just download the eclipse IDE with the dev tools packed in.

Ideally, use a Linux virtual machine for your C++ development. Using just the default programs installed with ubuntu is on par or slightly more friendly than trying to do development on windows. Additionally, Linux is incredibly convenient for things like version control, text manipulation, build options, etc...

On May 02 2014 02:43 bangsholt wrote:
To the UML discussion, let's dive into the two I've used the most.

Sequence diagrams:
This is very useful, when you're communicating with other services - then you can basically draw what happens when and why it happens. Alternative is to go to the source code and try to figure out what is going it - that's of course possible as well, but I would think it will take at least 3-4 times the time that it takes to look at the sequence diagram.

It's also good for when you are designing - if your interaction between whatever two things you are drawing looks awkward... It's probably because it is, and you should try to redesign it into something that's prettier and easier to understand.

Class diagram:

A very nice and simple way to get an overview of a whole system, but where it really shines in my opinion, is when you are designing your systems - because you do design before you code, RIGHT?

This makes it easy to whip up a design which you can then discuss with your fellow coders or engineers or whoever your team consists of.

What happens if you have 20 classes? You make two diagrams or more.

And added to this, most of the time the UML diagrams will always be slightly outdated in comparison to what is happening in the code, but you should strive to keep all your documentation to a high level and updated - it will make your life easier when you get back to something you wrote 5 months ago, and don't remember how to use.


Well put. UML is just another tool in your bag for designing a program, but code is a mutating organism, and you'll quickly find that trying to keep your design documents in line with your code is a losing battle.
Any sufficiently advanced technology is indistinguishable from magic
whiteLotus
Profile Blog Joined July 2009
1833 Posts
May 01 2014 18:50 GMT
#9445
ok guys i need some truth here, since i am currently going through codeacademy and other tutorials atm doing python, like it way more than php lel but nvm, there were a lot of tutorials where i had to use math, well basic math but still i suck even at that, and now that i am halfway through them, i need to know, can i become a decent (not microsoft level) >WEB< developer with only basic math like high shool level ? or am i eventually bound to fail when harder stuff than write a function that squares a number then write another function to check if that number is divisible by 3 if it is do that, if not do that comes around ?
The bird of Hermes is my name, eating my wings to make me tame
tofucake
Profile Blog Joined October 2009
Hyrule19266 Posts
May 01 2014 18:57 GMT
#9446
You don't generally need math for web development. Most math is specific to the job (I learned accounting at mine). Knowing discrete math or Calc 4 won't help you develop a financial backend system.
Liquipediaasante sana squash banana
Fawkes
Profile Blog Joined May 2010
Canada1935 Posts
May 01 2014 19:12 GMT
#9447
Had a question on some SQL proficiency test I was doing for fun. I haven't had a chance to work with transactions to understand exactly how commits and rollbacks work with multiple users. Don't know it exactly, but it went something like...

Two rows in a SQL table.
User A logs in.
User B logs in.
A pulls up the table.
B pulls up the table.
A adds 4 rows to the table.
B adds 6 rows to the table.
B commits.
C logs in and pulls the table.
C adds 10 rows to the table.
C commits.
A rollsback.

How many rows are in the table? My example might not work, I don't remember exactly what it was. My general questions are:

1. When commits happen, does it only commit that specific user's changes? Does this mean we lost A's row additions?
2. Does A's rollback do anything?

I don't know how to word the questions exactly, I just wish to learn about the nature of commit and rollbacks in a multiple user scenario.
Taeyeon ~ Jennie ~ Seulgi ~ Irene @Fawkes711
delHospital
Profile Blog Joined December 2010
Poland261 Posts
Last Edited: 2014-05-01 20:00:32
May 01 2014 19:24 GMT
#9448
How concurrent transactions work is not that simple, and depends on isolation level. You can read on it in Postgres' documentation, but keep in mind that this stuff differs from one database management system to another.

But in general, the idea is that changes executed in one transaction are invisible to concurrent transactions. If you rollback, it's as if the transaction never happened. Therefore, two transactions executed concurrently (and committed) either work as if they happened one after another or, if what happened is inconsistent with this view, the second commit fails.
Manit0u
Profile Blog Joined August 2004
Poland17868 Posts
May 01 2014 21:44 GMT
#9449
On May 02 2014 03:42 RoyGBiv_13 wrote:
Show nested quote +
On May 02 2014 01:27 tofucake wrote:
MinGW is also run through msys though, which is the whole unix environment thingy. Cygwin compiles against Cygwin.dll and can cause some issues if other versions of it are present on the target system. MinGW compiles into the program so that doesn't happen, but it's more complicated.


+1 for MinGW for your C++ compiler on windows. Alternatively, you can just download the eclipse IDE with the dev tools packed in.

Ideally, use a Linux virtual machine for your C++ development. Using just the default programs installed with ubuntu is on par or slightly more friendly than trying to do development on windows. Additionally, Linux is incredibly convenient for things like version control, text manipulation, build options, etc...

Show nested quote +
On May 02 2014 02:43 bangsholt wrote:
To the UML discussion, let's dive into the two I've used the most.

Sequence diagrams:
This is very useful, when you're communicating with other services - then you can basically draw what happens when and why it happens. Alternative is to go to the source code and try to figure out what is going it - that's of course possible as well, but I would think it will take at least 3-4 times the time that it takes to look at the sequence diagram.

It's also good for when you are designing - if your interaction between whatever two things you are drawing looks awkward... It's probably because it is, and you should try to redesign it into something that's prettier and easier to understand.

Class diagram:

A very nice and simple way to get an overview of a whole system, but where it really shines in my opinion, is when you are designing your systems - because you do design before you code, RIGHT?

This makes it easy to whip up a design which you can then discuss with your fellow coders or engineers or whoever your team consists of.

What happens if you have 20 classes? You make two diagrams or more.

And added to this, most of the time the UML diagrams will always be slightly outdated in comparison to what is happening in the code, but you should strive to keep all your documentation to a high level and updated - it will make your life easier when you get back to something you wrote 5 months ago, and don't remember how to use.


Well put. UML is just another tool in your bag for designing a program, but code is a mutating organism, and you'll quickly find that trying to keep your design documents in line with your code is a losing battle.


Best thing would be getting rid of Windows entirely (like I did 6 years ago) or dual-boot. Windows for games and .NET, Linux for everything else.
Time is precious. Waste it wisely.
delHospital
Profile Blog Joined December 2010
Poland261 Posts
May 01 2014 22:03 GMT
#9450
On May 02 2014 06:44 Manit0u wrote:
Show nested quote +
On May 02 2014 03:42 RoyGBiv_13 wrote:
On May 02 2014 01:27 tofucake wrote:
MinGW is also run through msys though, which is the whole unix environment thingy. Cygwin compiles against Cygwin.dll and can cause some issues if other versions of it are present on the target system. MinGW compiles into the program so that doesn't happen, but it's more complicated.


+1 for MinGW for your C++ compiler on windows. Alternatively, you can just download the eclipse IDE with the dev tools packed in.

Ideally, use a Linux virtual machine for your C++ development. Using just the default programs installed with ubuntu is on par or slightly more friendly than trying to do development on windows. Additionally, Linux is incredibly convenient for things like version control, text manipulation, build options, etc...

On May 02 2014 02:43 bangsholt wrote:
To the UML discussion, let's dive into the two I've used the most.

Sequence diagrams:
This is very useful, when you're communicating with other services - then you can basically draw what happens when and why it happens. Alternative is to go to the source code and try to figure out what is going it - that's of course possible as well, but I would think it will take at least 3-4 times the time that it takes to look at the sequence diagram.

It's also good for when you are designing - if your interaction between whatever two things you are drawing looks awkward... It's probably because it is, and you should try to redesign it into something that's prettier and easier to understand.

Class diagram:

A very nice and simple way to get an overview of a whole system, but where it really shines in my opinion, is when you are designing your systems - because you do design before you code, RIGHT?

This makes it easy to whip up a design which you can then discuss with your fellow coders or engineers or whoever your team consists of.

What happens if you have 20 classes? You make two diagrams or more.

And added to this, most of the time the UML diagrams will always be slightly outdated in comparison to what is happening in the code, but you should strive to keep all your documentation to a high level and updated - it will make your life easier when you get back to something you wrote 5 months ago, and don't remember how to use.


Well put. UML is just another tool in your bag for designing a program, but code is a mutating organism, and you'll quickly find that trying to keep your design documents in line with your code is a losing battle.


Best thing would be getting rid of Windows entirely (like I did 6 years ago) or dual-boot. Windows for games and .NET, Linux for everything else.

I disagree. Linux in a VM is surprisingly usable. And dual-boot is surprisingly annoying. Whenever I tried it, after some time I got fed up with constant reboots, and ended up doing everything under Windows.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-05-01 22:23:03
May 01 2014 22:22 GMT
#9451
On May 02 2014 07:03 delHospital wrote:
Show nested quote +
On May 02 2014 06:44 Manit0u wrote:
On May 02 2014 03:42 RoyGBiv_13 wrote:
On May 02 2014 01:27 tofucake wrote:
MinGW is also run through msys though, which is the whole unix environment thingy. Cygwin compiles against Cygwin.dll and can cause some issues if other versions of it are present on the target system. MinGW compiles into the program so that doesn't happen, but it's more complicated.


+1 for MinGW for your C++ compiler on windows. Alternatively, you can just download the eclipse IDE with the dev tools packed in.

Ideally, use a Linux virtual machine for your C++ development. Using just the default programs installed with ubuntu is on par or slightly more friendly than trying to do development on windows. Additionally, Linux is incredibly convenient for things like version control, text manipulation, build options, etc...

On May 02 2014 02:43 bangsholt wrote:
To the UML discussion, let's dive into the two I've used the most.

Sequence diagrams:
This is very useful, when you're communicating with other services - then you can basically draw what happens when and why it happens. Alternative is to go to the source code and try to figure out what is going it - that's of course possible as well, but I would think it will take at least 3-4 times the time that it takes to look at the sequence diagram.

It's also good for when you are designing - if your interaction between whatever two things you are drawing looks awkward... It's probably because it is, and you should try to redesign it into something that's prettier and easier to understand.

Class diagram:

A very nice and simple way to get an overview of a whole system, but where it really shines in my opinion, is when you are designing your systems - because you do design before you code, RIGHT?

This makes it easy to whip up a design which you can then discuss with your fellow coders or engineers or whoever your team consists of.

What happens if you have 20 classes? You make two diagrams or more.

And added to this, most of the time the UML diagrams will always be slightly outdated in comparison to what is happening in the code, but you should strive to keep all your documentation to a high level and updated - it will make your life easier when you get back to something you wrote 5 months ago, and don't remember how to use.


Well put. UML is just another tool in your bag for designing a program, but code is a mutating organism, and you'll quickly find that trying to keep your design documents in line with your code is a losing battle.


Best thing would be getting rid of Windows entirely (like I did 6 years ago) or dual-boot. Windows for games and .NET, Linux for everything else.

I disagree. Linux in a VM is surprisingly usable. And dual-boot is surprisingly annoying. Whenever I tried it, after some time I got fed up with constant reboots, and ended up doing everything under Windows.


Get the best of both worlds, two computers.
+ Show Spoiler +

windows gaming desktop + linux programming laptop is my home setup
two desktop workstations, one of each, with synergy so they share a mouse and keyboard for my work setup.
Any sufficiently advanced technology is indistinguishable from magic
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-05-01 22:22:50
May 01 2014 22:22 GMT
#9452
crap, double post :/
Any sufficiently advanced technology is indistinguishable from magic
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2014-05-02 02:03:27
May 02 2014 01:53 GMT
#9453
If you don't run a version of linux when you're doing non-Windows development you're doing yourself a huge disservice.

That said, I think once you've installed MinGW and its MSYS components, and you learn a bit about how to screw around with your environment PATH variable, you're in great shape for Windows only. There's not much else you need other than to replace the command prompt with either Git Bash << Console2 << ConEmu shell. Sometimes I prefer Linux because it feels a lot more hack-y than Windows, and using Debian flavours means I'm an apt-get away from downloading any new packages I need to help development, but usually Windows is popular enough to have a port available and sometimes I prefer having the installer do things for me (Windows has a huge leg up over Ubuntu because of this I feel).

I'm a bit biased since I use Windows products more, but I'm much more effective doing things on Windows than I am somewhere else. I think if you can get over the initial entry barrier to Windows development it's actually pretty much on par with a lot of unix systems until you hit stumbling blocks because there's no Windows-variant of something you need, which isn't that common but is a bit annoying. You can say the same the other way though


edit: forgot to say, piping makes things amazing, i really wish windows did it better o: and by better i mean at all'

edit2: holy shit you can pipe in windows
There is no one like you in the universe.
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
May 02 2014 16:50 GMT
#9454
On May 02 2014 04:12 Fawkes wrote:
Had a question on some SQL proficiency test I was doing for fun. I haven't had a chance to work with transactions to understand exactly how commits and rollbacks work with multiple users. Don't know it exactly, but it went something like...

Two rows in a SQL table.
User A logs in.
User B logs in.
A pulls up the table.
B pulls up the table.
A adds 4 rows to the table.
B adds 6 rows to the table.
B commits.
C logs in and pulls the table.
C adds 10 rows to the table.
C commits.
A rollsback.

How many rows are in the table? My example might not work, I don't remember exactly what it was. My general questions are:

1. When commits happen, does it only commit that specific user's changes? Does this mean we lost A's row additions?
2. Does A's rollback do anything?

I don't know how to word the questions exactly, I just wish to learn about the nature of commit and rollbacks in a multiple user scenario.

My only experience is with Microsoft SQL server, and from that context the answer would be 16. User A's rows would be rolled back as one single transaction, but the other User's transactions would commit, effectively adding 16 rows. Things can get tricky when you start asking what the table values are during those transactions, and there is more than one way to define how you want that to work. But since you're only asking how many rows are in the table after everything is finished, there is no conflict between the transactions.
Beamer
Profile Joined March 2010
United States242 Posts
Last Edited: 2014-05-02 20:49:36
May 02 2014 20:44 GMT
#9455
I'm trying to understand the underlying difference between these methods of populating a vector in C++:

Let's say I have a Rectangle class with a constructor which takes in 2 double values, length and width. Also, I have a container class that is used to hold a bunch of Rectangle objects, called RectanglePack. This RectanglePack stores Rectangle objects in a vector. I want to add 10 Rectangles to RectanglePack. Here's one way I could do this:

+ Show Spoiler [Method 1] +
// Method 1

for(int i = 1; i <= 10; i++)
{
mRectanglePack.Add(new Rectangle(1, i));
}


In this case, RectanglePack.Add receives a Rectangle pointer and adds it to the vector like this:

+ Show Spoiler +
void RectanglePack::Add(Rectangle* rectangle)
{
mRectangleVector.push_back(rectangle) // this vector stores Rectangle pointers
}


Another way I could implement this is the following:

+ Show Spoiler [Method 2] +
// Method 2

for(int i = 1; i <= 10; i++)
{
Rectangle rectangle(1, i)
mRectanglePack.Add(rectangle);
}


In this case, RectanglePack.Add receives an actual Rectangle object and adds it to the vector like this:

+ Show Spoiler +
void RectanglePack::Add(Rectangle rectangle)
{
mRectangleVector.push_back(rectangle) // this vector stores Rectangle objects
}


One last way I could implement this is by using the following:

+ Show Spoiler [Method 3] +
// Method 3

for(int i = 1; i <= 10; i++)
{
Rectangle rectangle = new Rectangle(1, i)
mRectanglePack.Add(*rectangle);
}


I think Method 1 and Method 3 are very similar. The only difference is that one vector holds the pointers to the Rectangle objects and the other vector holds the actual Rectangle objects. Also, Method 1 and Method 3 both have to worry about deallocating memory eventually. I think Method 2 is a little different in that it creates a copy of the Rectangle object in Rectangle::Add and pushes the copy into the vector. However, I'm not sure if my understanding is correct. Also, is there a certain convention for something like this? Is one way preferred over the other ways for some reason?
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2014-05-02 22:13:31
May 02 2014 22:13 GMT
#9456
On May 03 2014 05:44 Beamer wrote:
I'm trying to understand the underlying difference between these methods of populating a vector in C++:

Let's say I have a Rectangle class with a constructor which takes in 2 double values, length and width. Also, I have a container class that is used to hold a bunch of Rectangle objects, called RectanglePack. This RectanglePack stores Rectangle objects in a vector. I want to add 10 Rectangles to RectanglePack. Here's one way I could do this:

+ Show Spoiler [Method 1] +
// Method 1

for(int i = 1; i <= 10; i++)
{
mRectanglePack.Add(new Rectangle(1, i));
}


In this case, RectanglePack.Add receives a Rectangle pointer and adds it to the vector like this:

+ Show Spoiler +
void RectanglePack::Add(Rectangle* rectangle)
{
mRectangleVector.push_back(rectangle) // this vector stores Rectangle pointers
}


Another way I could implement this is the following:

+ Show Spoiler [Method 2] +
// Method 2

for(int i = 1; i <= 10; i++)
{
Rectangle rectangle(1, i)
mRectanglePack.Add(rectangle);
}


In this case, RectanglePack.Add receives an actual Rectangle object and adds it to the vector like this:

+ Show Spoiler +
void RectanglePack::Add(Rectangle rectangle)
{
mRectangleVector.push_back(rectangle) // this vector stores Rectangle objects
}


One last way I could implement this is by using the following:

+ Show Spoiler [Method 3] +
// Method 3

for(int i = 1; i <= 10; i++)
{
Rectangle rectangle = new Rectangle(1, i)
mRectanglePack.Add(*rectangle);
}


I think Method 1 and Method 3 are very similar. The only difference is that one vector holds the pointers to the Rectangle objects and the other vector holds the actual Rectangle objects. Also, Method 1 and Method 3 both have to worry about deallocating memory eventually. I think Method 2 is a little different in that it creates a copy of the Rectangle object in Rectangle::Add and pushes the copy into the vector. However, I'm not sure if my understanding is correct. Also, is there a certain convention for something like this? Is one way preferred over the other ways for some reason?

Your understanding is nearly correct, and this link is relavent: http://stackoverflow.com/questions/655065/when-should-i-use-the-new-keyword-in-c

Method 1&3 are semantically the same, and the rectangle variable will get optimized out by the compiler, with a pointer to the new rectangle being placed directly on the stack for the mRectanglePack.Add() function. Any time you see the "new" keyword, it's probably going to be placed on the heap (technically "free store"). As you mentioned, that memory will need to be cleaned up, so you may want to stick with Method 3, and bookkeep those pointers separately if you are uncomfortable deleting everything in the Vector.

Method 2 is placing the rectangle objects on the stack, then passing by value. This creates another copy on the stack, for the Add() function. This function is going to create a third copy in push_back(). I have no clue how push_back stores the value, but let's assume is does the right thing and saves off the value passed to it on the stack so it doesn't lose it. Then the three copies will be popped off the stack as it goes back into the for loop.

There is no convention for this, it's a judgement call. Just so long as you aren't doing:

or(int i = 1; i <= 10; i++)
{
Rectangle rectangle(1, i)
mRectanglePack.Add(&rectangle);
}
Any sufficiently advanced technology is indistinguishable from magic
nunez
Profile Blog Joined February 2011
Norway4003 Posts
Last Edited: 2014-05-02 23:49:37
May 02 2014 23:41 GMT
#9457
i'll try complement roygbiv's answer with some general input, at best tangential to your actual post filled with contrived examples.

re:interface

in method 2 - if you use Rectangle const& in your add function for lvalues and an overload for with Rectangle&& for rvalue refs you might avoid unecessary copies (if your rectangle class does not have move-semantics the rvalue ref overload is pontless tough):

#include<iostream>
#include<vector>
#include<utility>

using namespace std;

struct imba_t{
imba_t(){ std::cout<<"def ctor\n"; }
imba_t(imba_t const&){ std::cout<<"cpy ctor\n"; }
imba_t(imba_t&&){ std::cout<<"mov ctor\n"; }
};

class protoss_t{
vector<imba_t> death_ball;
public:
protoss_t(){ death_ball.reserve(5); } //reserve some space
void ref_add(imba_t const& unit){ death_ball.push_back(unit); }
void mov_add(imba_t&& unit){ death_ball.push_back(std::move(unit)); }
void cpy_add(imba_t unit){ death_ball.push_back(unit); }
};

int main(){
protoss_t protoss;
imba_t zealot;
std::cout<<"\npassing imba unit by const ref\n";
protoss.ref_add(zealot);
std::cout<<"passing imba unit by rvalue ref\n";
protoss.mov_add(imba_t());
imba_t sentry;
std::cout<<"\npassing imba unit by value\n";
protoss.cpy_add(sentry);
}

output:

[jeh@gimli tl]$ ./tl 
def ctor <- zealot contructed
passing imba unit by const ref
cpy ctor
passing imba unit by rvalue ref
def ctor <-unnamed imba_t constructed
mov ctor
def ctor <- sentry constructed
passing imba unit by value
cpy ctor
cpy ctor

when add is called with an rvalue reference (temporary variable) it moves the imba_t instead of copying!
when add is called with a const reference it only does one copy.
when add is called with argument by value it only does two copies, one to copy into function and one to copy into vector.

instead of working with raw pointers you can use automatic memory management with unique_ptr or shared_ptr instead:

#include<iostream>
#include<memory>
#include<vector>
#include<utility>

using namespace std;

struct imba_t{
imba_t(){ std::cout<<"def ctor\n"; }
imba_t(imba_t const&){ std::cout<<"cpy ctor\n"; }
imba_t(imba_t&&){ std::cout<<"mov ctor\n"; }
~imba_t(){ std::cout<<"dtor\n"; }
};

typedef shared_ptr<imba_t> imba_ptr_t;

class protoss_t{
vector<imba_ptr_t> death_ball;
public:
protoss_t(){ death_ball.reserve(5); }
void add(imba_ptr_t const& unit){ std::cout<<"cpy ptr\n"; death_ball.push_back(unit); }
void add(imba_ptr_t&& unit){ std::cout<<"mov ptr\n"; death_ball.push_back(std::move(unit)); }
};

int main(){
imba_ptr_t zealot=make_shared<imba_t>();
{
protoss_t protoss;
std::cout<<"passing imba unit by const ref\n";
protoss.add(zealot);
std::cout<<"passing imba unit by rvalue ref\n";
protoss.add(make_shared<imba_t>());
std::cout<<"passing imba unit by value\n";
}
std::cout<<"protoss gone, zealot still here\n";
}

[jeh@gimli tl]$ ./tl 
def ctor
passing imba unit by const ref
cpy ptr
passing imba unit by rvalue ref
def ctor
mov ptr
passing imba unit by value
dtor <- unnamed imba_t destructed
protoss gone, zealot still here
dtor <- zealot destructed

they support copy / move semantics in the same way as the previous example (except now it's the pointer being copied or moved), and the destructor is automatically called when the reference count goes down to 0 (with shared_ptr).

re:initalization

i'd maybe use reserve and emplace_back, constructing the elements in-place bypassing copy/move all together and ~explicitly allocating the blob of memory the vector needs (imba_t ctor takes int):

	vector<imba_t> death_ball;
int N=10;
death_ball.reserve(N);
for(int i=0;i<N;++i) death_ball.emplace_back(i);

or, if possible and your compiler is up to snuff use ctor number 7 from vector with an initializer_list (imba_t ctor takes int and char):

	vector<imba_t> death_ball({{0,'b'},{1,'c'},{2,'f'}});


maybe make a ctor for your rectangle container that takes an initializer list for your rectangles as argument. if rvalue references are too daunting just stick to const&, an rvalue will bind to it so you can still write .add(imba_t()); except it will copy it into the vector instead of move.

alternatively you could also use generate_n and a lambda or functor:

	int i=0,N=10;
vector<imba_t> death_ball;
generate_n(begin(death_ball),N,[&](){
return ++i;
});
conspired against by a confederacy of dunces.
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2014-05-03 00:10:56
May 03 2014 00:04 GMT
#9458
EDIT: I was wrong, read the post wrong ^^

edit2: So one thing - methods 1 and 3 aren't exactly similar.
Add(new Rectangle)
pushes back a pointer, while
Add(*rectangle)
pushes back a copy of the new rectangle you allocated. If the third method was written as
Add(rectangle)
ie. passing the pointer instead of dereferencing it, then they're functionally the same. And Method 1 won't be able to deallocate the memory once that loop is done - it pushes back copies, not the actual objects, so you'll be creating heap-allocated rectangles that you can't get rid of until your program dies.

Method 2 is probably the most idiomatic - don't allocate memory manually if you don't have to =)
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2014-05-03 00:16:32
May 03 2014 00:09 GMT
#9459
So I had to format text recently, and give it back with no tags (and also without text/stuff inside tags), but I couldn't come up with something more than just erasing tags.

Basically it's like:


Text. <script> whatever text </script> More text.


The idea is to just return

Text. More text.


But how is this done? Regex/Pattern matching easily comes to mind, but I don't really understand it that well. I use Java, so an example for Java would be better.

String#replaceAll("\\<[^>]*>","")
only clears tags.
phar
Profile Joined August 2011
United States1080 Posts
May 03 2014 02:13 GMT
#9460
First off, don't parse what is essentially xml with a regex:

http://stackoverflow.com/questions/6751105

You could probably use something like JAXP.




If you can guarantee that there are no nested tags you could probably do it with regex.
Who after all is today speaking about the destruction of the Armenians?
Prev 1 471 472 473 474 475 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 40m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft597
StarCraft: Brood War
Rain 2569
Hyuk 224
Larva 158
Bisu 152
ProTech103
Mong 85
sorry 85
Leta 38
Killer 35
ZergMaN 34
[ Show more ]
Shine 34
ggaemo 31
soO 22
yabsab 18
Aegong 16
Noble 15
Dota 2
ODPixel316
League of Legends
JimRising 870
Counter-Strike
fl0m3372
Super Smash Bros
Mew2King125
Other Games
summit1g13538
ceh9378
Organizations
Other Games
gamesdonequick766
Counter-Strike
PGL447
StarCraft: Brood War
lovetv 5
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Laughngamez YouTube
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2231
League of Legends
• Stunt487
Upcoming Events
WardiTV Weekly
3h 40m
Ultimate Battle
3h 40m
Rush vs BeSt
Replay Cast
14h 40m
Rogue vs Classic
Patches Events
1d 4h
PiGosaur Cup
1d 16h
Kung Fu Cup
2 days
Replay Cast
2 days
The PondCast
3 days
KCM Race Survival
3 days
IntoTheTV X SOOP
5 days
herO vs Rogue
Reynor vs Solar
ByuN vs SHIN
Clem vs MaxPax
[ Show More ]
WardiTV Invitational
5 days
IPSL
5 days
WorsT vs nOmaD
Dewalt vs andersOn
IntoTheTV X SOOP
6 days
WardiTV Invitational
6 days
IPSL
6 days
Azhi_Dahaki vs ggnore13
Double vs WIZARD
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-11-01
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
BSL Season 23
IPSL Winter 2026-27
IEM Beijing 2026
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026

Upcoming

1xBet Invitational
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
BLAST Bounty Winter 2027
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 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.