• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:52
CEST 13:52
KST 20:52
  • 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
Code S Season 1 - RO8 Preview1[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event11Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced9
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
GSL Code S Season 1 (2026) Sparkling Tuna Cup - Weekly Open Tournament RSL Revival: Season 5 - Qualifiers and Main Event StarCraft Evolution League (SC Evo Biweekly) 2026 GSL Season 2 Qualifiers
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
(Spoiler) Asl ro8 D winner interview BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Do we have a pimpest plays list? AI Question
Tourneys
[ASL21] Ro8 Day 3 [ASL21] Ro8 Day 4 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV OutLive 25 (RTS Game) Daigo vs Menard Best of 10 Nintendo Switch Thread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
European Politico-economics QA Mega-thread US Politics Mega-thread Russo-Ukrainian War Thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1676 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
Hyrule19210 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
Hyrule19210 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
Poland17743 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
GSL
09:30
2026 Season 1: Ro8 Group A
Cure vs MaruLIVE!
Classic vs Rogue
IntoTheiNu 447
Ryung 384
CranKy Ducklings SOOP99
herO (SOOP)63
Rex43
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Ryung 384
Lowko305
herO (SOOP) 63
Rex 43
StarCraft: Brood War
Britney 37601
Calm 5899
BeSt 1150
Horang2 770
Hyuk 598
EffOrt 469
Stork 358
Mini 247
actioN 245
Last 175
[ Show more ]
Soulkey 171
Rush 170
ggaemo 165
Snow 163
Soma 162
Mind 114
ZerO 109
hero 101
Killer 95
Pusan 87
Hyun 87
Mong 66
Backho 57
Shine 44
Aegong 40
sSak 32
Bale 26
soO 25
Barracks 20
Sacsri 20
Icarus 19
GoRush 16
Dewaltoss 15
Noble 13
IntoTheRainbow 11
ajuk12(nOOB) 8
SilentControl 7
Terrorterran 4
Counter-Strike
olofmeister2407
zeus940
byalli450
x6flipin327
allub279
edward101
kRYSTAL_42
Super Smash Bros
Westballz24
Other Games
singsing1580
B2W.Neo498
monkeys_forever110
ArmadaUGS16
ZerO(Twitch)6
Organizations
Other Games
gamesdonequick568
StarCraft: Brood War
UltimateBattle 48
Dota 2
PGL Dota 2 - Main Stream25
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• Noizen35
League of Legends
• Jankos1277
Other Games
• WagamamaTV74
Upcoming Events
GSL
21h 38m
SHIN vs Zoun
ByuN vs herO
OSC
23h 8m
OSC
1d 1h
Replay Cast
1d 12h
Escore
1d 22h
The PondCast
1d 22h
WardiTV Invitational
1d 23h
Zoun vs Ryung
Lambo vs ShoWTimE
OSC
2 days
Replay Cast
2 days
CranKy Ducklings
2 days
[ Show More ]
RSL Revival
2 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
2 days
Krystianer vs TriGGeR
Cure vs Rogue
uThermal 2v2 Circuit
3 days
BSL
3 days
Replay Cast
3 days
Sparkling Tuna Cup
3 days
RSL Revival
3 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
3 days
BSL
4 days
GSL
4 days
Afreeca Starleague
4 days
Soma vs Leta
Monday Night Weeklies
5 days
CranKy Ducklings
5 days
Afreeca Starleague
5 days
Light vs Flash
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
YSL S3
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.