• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 15:30
CEST 21:30
KST 04:30
  • 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] Ro16 Preview: Holy Diver3[ASL22] Ro16 Preview: Rough Waters10[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915
Community News
StarCraft open world shooter announced at BlizzCon74Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism10Official StarCraft website teases new content ahead of BlizzCon?173Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3
StarCraft 2
General
StarCraft open world shooter announced at BlizzCon How do you feel about the StarCraft shooter announcement at BlizzCon 2026? Balance hotfix patch 5.0.16b (July 16) Team Liquid Map Contest #22: Results and Winners Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism
Tourneys
RSL Revival: Season 6 - Qualifiers and Main Event RSL goes to London! 2026 Offline Finals Nov 21-22 Sparkling Tuna Cup - Weekly Open Tournament KSL Week #92 IntoTheTV X SOOP SC2 League : Weekly & Monthly
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 543 Enhanced Defenses The PondCast: SC2 News & Results Mutation # 542 The Ascended Mutation # 541 Binary Choice
Brood War
General
[ASL22] Ro16 Preview: Holy Diver Official StarCraft website teases new content ahead of BlizzCon? ASL22 General Discussion BGH Auto Balance -> http://bghmmr.eu/ Broodwar Prediction Market
Tourneys
[ASL22] Ro16 Group C [ASL22] Ro16 Group B [ASL22] Ro16 Group A Escore Tournament - Season 3
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
Diablo IV Nintendo Switch Thread EVE Corporation [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
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 UK Politics Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread Russo-Ukrainian War Thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Diablo Animated Series on Netflix
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
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Virtual Romance, Real-Life C…
TrAiDoS
Regacy Esports:Our Goa…
regacyesports
Dreaming of BW patches (mod…
c3rberUs
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 9205 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
Hyrule19254 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
Hyrule19254 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
Poland17843 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
BlizzCon
18:30
Blizzard Classic Cup 2026
IdrA vs MC
StarCraft2397
RotterdaM1090
ComeBackTV 774
TaKeTV 321
IndyStarCraft 253
EnkiAlexander 80
CosmosSc2 66
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 1090
IndyStarCraft 253
StarCraft: Brood War
Britney 20857
Calm 2864
Shuttle 1005
Artosis 726
Mini 177
firebathero 128
Dewaltoss 119
CosmosSc2 66
Trap 24
Mong 22
[ Show more ]
sSak 19
League of Legends
goblin6
Counter-Strike
byalli1082
Super Smash Bros
C9.Mang0337
hungrybox301
Mew2King167
Chillindude19
Heroes of the Storm
Liquid`Hasu550
MindelVK16
Other Games
summit1g6818
Grubby5771
Liquid`RaSZi2330
fl0m947
Tasteless683
Mlord532
B2W.Neo435
mouzStarbuck325
Pyrionflax207
Hui .130
XaKoH 115
Organizations
Other Games
gamesdonequick2445
EGCTV1505
Heroes of the Storm
Heroes of the Storm643
StarCraft: Brood War
Afreeca ASL 543
[ Show 15 non-featured ]
StarCraft 2
• Berry_CruncH436
• Hupsaiya 49
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Azhi_Dahaki37
• blackmanpl 12
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3092
• masondota21305
Other Games
• Shiphtur240
Upcoming Events
Afreeca Starleague
14h 30m
Light vs JyJ
Soulkey vs hero
WardiTV Weekly
15h 30m
Monday Night Weeklies
20h 30m
Afreeca Starleague
1d 14h
Snow vs Shinee
Shine vs EffOrt
GSL
1d 15h
PiGosaur Cup
2 days
The PondCast
2 days
Kung Fu Cup
2 days
Replay Cast
3 days
KCM Race Survival
3 days
[ Show More ]
IntoTheTV X SOOP
3 days
Replay Cast
4 days
IntoTheTV X SOOP
4 days
Replay Cast
5 days
GSL
5 days
Replay Cast
6 days
GSL
6 days
Shopify Rebellion Sundays
6 days
Spirit vs Mixu
Liquipedia Results

Completed

Acropolis #5 - TRS
PiG Sty Festival 8.0
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Blizzard Classic Cup 2026
Blizzard Classic Cup 2026
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
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
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.