• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 18:41
CET 00:41
KST 08:41
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Which season is the best in ASL? BW General Discussion Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
ZeroSpace Megathread Stormgate/Frost Giant Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1760 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
Hyrule19167 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
Hyrule19167 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
Poland17495 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 19m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft262
elazer 150
SpeCial 35
CosmosSc2 30
StarCraft: Brood War
Artosis 389
Larva 134
Dota 2
syndereN1082
League of Legends
C9.Mang090
Counter-Strike
Foxcn271
Other Games
Grubby5719
tarik_tv4103
FrodaN854
summit1g734
RotterdaM161
Maynarde108
ArmadaUGS82
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• HeavenSC 54
• musti20045 36
• davetesta19
• Kozan
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• RayReign 48
• blackmanpl 30
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler99
League of Legends
• Doublelift4289
Other Games
• imaqtpie1424
• Shiphtur243
Upcoming Events
Replay Cast
19m
The PondCast
10h 19m
OSC
16h 19m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
1d
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
[ Show More ]
Sparkling Tuna Cup
3 days
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
5 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
6 days
StarCraft2.fi
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

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

Advertising | Privacy Policy | Terms Of Use | Contact Us

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