• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 20:30
CEST 02:30
KST 09: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
[ASL20] Ro24 Preview Pt2: Take-Off6[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax5Maestros of The Game—$20k event w/ live finals in Paris30Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
Weekly Cups (Aug 18-24): herO dethrones MaxPax What mix of new and old maps do you want in the next 1v1 ladder pool? (SC2) : A Eulogy for the Six Pool Geoff 'iNcontroL' Robinson has passed away 2v2 & SC: Evo Complete: Weekend Double Feature
Tourneys
WardiTV Mondays Maestros of The Game—$20k event w/ live finals in Paris RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament Monday Nights Weeklies
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
No Rain in ASL20? BW General Discussion Flash On His 2010 "God" Form, Mind Games, vs JD BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ro24 Preview Pt2: Take-Off
Tourneys
[ASL20] Ro24 Group E [Megathread] Daily Proleagues [ASL20] Ro24 Group D [ASL20] Ro24 Group B
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread General RTS Discussion Thread Dawn of War IV 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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5999 users

The Big Programming Thread - Page 199

Forum Index > General Forum
Post a Reply
Prev 1 197 198 199 200 201 1031 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.
Schokomuesli
Profile Joined November 2010
Germany12 Posts
November 20 2012 10:41 GMT
#3961
I don't know if I get you right but this here should work (no compiler here, so don't trust my syntax ;-) )

std::vector<std::pair<std::string, int>>> myVec;
for (auto v : myVec) {
std::cout << [] (std::pair<std::string, int>& x) {return x.second;} (v) << std::endl;
}
//^ this should work
std::for_each (myVec.begin(), myVec.end(); [&] (std::pair<std::string, int>& x) {std::cout << x.second << std::endl;})
// ^this, too


Binary sizes are usually no problem - if you are not developing in an embedded environment where you might only have a limited amount of storage etc...
heishe
Profile Blog Joined June 2009
Germany2284 Posts
November 20 2012 10:58 GMT
#3962
On November 20 2012 18:05 Fyodor wrote:
Show nested quote +
On November 20 2012 17:36 Schokomuesli wrote:
In C++11 you can define all your return types using (a form of) this syntax. You don't have to declare them in Lambdas if the return type is deductible by the compiler.

From wikipedia:

[](int x, int y) { return x + y; }
The return type is implicit; it returns the type of the return expression (decltype(x+y)). The return type of a lambda can be omitted as long as all return expressions return the same type.


The other kind mostly has its uses in template functions I guess...
template<class Lhs, class Rhs>
auto adding_func(const Lhs &lhs, const Rhs &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}


On November 20 2012 15:48 Fyodor wrote:
On November 20 2012 15:43 Morfildur wrote:
On November 20 2012 15:24 Fyodor wrote:
C++ right

using VS2012, my lambdas have weird return types. I try like

std::cout << [] () -> int {return 12;};


the right hand side gives me a return type of "lambda []int () -> int". Shouldn't that return a simple int or is there something I'm not grasping?


I haven't worked with C++ lambdas but judging from the little that i know, it looks like you are passing the lambda function itself, you don't execute it and pass the result.

oh so that's why this works?


auto f = [] () {return 12;};


std::cout << f();


^ in this case f is of function type (std::function<int> in this case). The compiler actually turns this into a function which will end up in your binary - even if you use it just once. So using _many_ lambdas will increase your binary size... but then if this really matters to you, you probably won't be using C++ in the first place ;-)

So how do I use lambdas without making them function types? I've seen them tossed in as the third element in a for loop but it won't return me an int that I can print.

Also are big binaries much of a problem really? I thought there was no strong relation between code size and performance.


If you want to use lambdas, you have to capture them first ("save them to a variable"). auto x = [](whatever){}; x(); Every function you use that takes lambdas does the same thing, just implicitly through template argument deduction.

Also while big binaries aren't a guarantee for less optimal performance than the same product with different code and smaller binaries, if you go above a certain size it's certainly an indicator of bad performance. This is because apart from a data cache, CPUs also have instruction caches, where the store and read all the machine code instructions that your code consists off. If you have more code, less stuff will fit into the cache, and you will have more cache misses, etc.

But I've actually never seen code where instruction cache misses are a performance issue that takes away more than 0.001% of your performance. But then again I've never programmed for consoles or mobile devices.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Bigpet
Profile Joined July 2010
Germany533 Posts
Last Edited: 2012-11-21 03:15:10
November 20 2012 12:57 GMT
#3963
On November 20 2012 18:05 Fyodor wrote:
Show nested quote +
On November 20 2012 17:36 Schokomuesli wrote:
In C++11 you can define all your return types using (a form of) this syntax. You don't have to declare them in Lambdas if the return type is deductible by the compiler.

From wikipedia:

[](int x, int y) { return x + y; }
The return type is implicit; it returns the type of the return expression (decltype(x+y)). The return type of a lambda can be omitted as long as all return expressions return the same type.


The other kind mostly has its uses in template functions I guess...
template<class Lhs, class Rhs>
auto adding_func(const Lhs &lhs, const Rhs &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}


On November 20 2012 15:48 Fyodor wrote:
On November 20 2012 15:43 Morfildur wrote:
On November 20 2012 15:24 Fyodor wrote:
C++ right

using VS2012, my lambdas have weird return types. I try like

std::cout << [] () -> int {return 12;};


the right hand side gives me a return type of "lambda []int () -> int". Shouldn't that return a simple int or is there something I'm not grasping?


I haven't worked with C++ lambdas but judging from the little that i know, it looks like you are passing the lambda function itself, you don't execute it and pass the result.

oh so that's why this works?


auto f = [] () {return 12;};


std::cout << f();


^ in this case f is of function type (std::function<int> in this case). The compiler actually turns this into a function which will end up in your binary - even if you use it just once. So using _many_ lambdas will increase your binary size... but then if this really matters to you, you probably won't be using C++ in the first place ;-)

So how do I use lambdas without making them function types? I've seen them tossed in as the third element in a for loop but it won't return me an int that I can print.

Also are big binaries much of a problem really? I thought there was no strong relation between code size and performance.


isn't it kind of obvious?


std::cout << ([]()->int{return 12;})();


you need to actually execute the lambda not just define it

edit: yeah, I just repeated schockos first example but all the namespace accessors and template parameters just slightly hid what he was missing.
I'm NOT the caster with a similar nick
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
Last Edited: 2012-11-20 18:06:15
November 20 2012 17:48 GMT
#3964
On November 20 2012 21:57 Bigpet wrote:
Show nested quote +
On November 20 2012 18:05 Fyodor wrote:
On November 20 2012 17:36 Schokomuesli wrote:
In C++11 you can define all your return types using (a form of) this syntax. You don't have to declare them in Lambdas if the return type is deductible by the compiler.

From wikipedia:

[](int x, int y) { return x + y; }
The return type is implicit; it returns the type of the return expression (decltype(x+y)). The return type of a lambda can be omitted as long as all return expressions return the same type.


The other kind mostly has its uses in template functions I guess...
template<class Lhs, class Rhs>
auto adding_func(const Lhs &lhs, const Rhs &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}


On November 20 2012 15:48 Fyodor wrote:
On November 20 2012 15:43 Morfildur wrote:
On November 20 2012 15:24 Fyodor wrote:
C++ right

using VS2012, my lambdas have weird return types. I try like

std::cout << [] () -> int {return 12;};


the right hand side gives me a return type of "lambda []int () -> int". Shouldn't that return a simple int or is there something I'm not grasping?


I haven't worked with C++ lambdas but judging from the little that i know, it looks like you are passing the lambda function itself, you don't execute it and pass the result.

oh so that's why this works?


auto f = [] () {return 12;};


std::cout << f();


^ in this case f is of function type (std::function<int> in this case). The compiler actually turns this into a function which will end up in your binary - even if you use it just once. So using _many_ lambdas will increase your binary size... but then if this really matters to you, you probably won't be using C++ in the first place ;-)

So how do I use lambdas without making them function types? I've seen them tossed in as the third element in a for loop but it won't return me an int that I can print.

Also are big binaries much of a problem really? I thought there was no strong relation between code size and performance.


isn't it kind of obvious?


std::cout << ([]()->int{return 12;})();


you need to actually execute the lambda not just define it

Bingo, that's exactly what I needed, thank you so much.

thank you others for helping too. Still trying to read schokomuesli's post
llllllllllllllllllllllllllllllllllllllllllll
Nobu
Profile Joined June 2010
Spain550 Posts
Last Edited: 2012-11-21 20:15:50
November 21 2012 12:28 GMT
#3965
Hey guys! need a bit of help from someone with java code. This is the thing.

I need to write a class that add two matrices in a concurrent way extending from the Thread class. Then I need to write a new class that using the previous class add two matrices. I have both implemented already and they look like this:

addMatrices

fields:
public static float[][] m;
public static float[][] n;
private static float[][] res;
private static int filas;//rows
private static int columnas;//columns
private int fila;// specific row that the thread will add

methods:
public sumaMatConcurrente(float [][] mat1, float[][] mat2) //Constructor that clone mat1 and mat2 into m and n fields.
private sumaMatConcurrente(int row) //Constructor that I used to initialize field fila, which will control which row of the
//matrix will resolve each thread
public void run()//Save the result of the add of the specific row into res matrix;
public float[][] Suma() //Creates an array of threads and launch them to resolve the operation. Then return the result.


SOOOOOO... here's the thing. We also had to create a class that does the same thing in a non concurrent way and that one is working faster than the one that's concurrent -_-. My guess is, that because I have to actually copy both matrices into the static fields in order to do this in a threaded way, the program is cloning 2 more matrices, and when the dimension of them are like 10000x10000 it's probably making the threaded one slower than the other one.

So finally my question. Is there a way to actually implement this without the need of the 2 static fields that save the two matrices and still make this work with threads??? Just to clarify, the 3 classes work already, i just wondered if there is a better way to do it in a concurrent way without having to clone the static fields.

Hope i explained myself well, im going to leave the code for the 3 classes here in spoilers just in case it wasnt clear enough

Thx a lot guys, love this thread <3

EDIT: Didnt know about the code blocks, already fixed.

Class sumaMat (Non concurrent way of adding two matrices, that works faster)
+ Show Spoiler +

public class sumaMat{
//this method will add both matrices and return the resulting one.
public static float[][] suma(float[][] mat1,float[][] mat2){
if(mat1.length!=mat2.length || mat1[0].length!=mat2[0].length){
System.out.println("Las matrices no son de la misma dimension por lo que no se pueden sumar");
System.out.println("El objeto no se ha iniciado correctamente, vuelva a inicializarlo o el resultado no sera correcto");
System.exit(1);
return(mat1);
}
else{
float[][]res=new float[mat1.length][mat1[0].length];
for(int i=0;i<mat1.length;i++){
for(int j=0;j<mat1[0].length;j++){
res[i][j]=mat1[i][j]+mat2[i][j];
}
}
return(res);
}
}

//main method that create the matrices then add them
public static void main(String[] args){
int filas=10000;
int columnas=10000;
float[][] m,n,res;
res=new float[filas][columnas];
m=new float[filas][columnas];
for(int i=0;i<filas;i++){
for(int j=0;j<columnas;j++){
m[i][j]=1.0f;
}
}
n=m.clone();
m=sumaMat.suma(m, n).clone();
}

}


Class sumaMatConcurrente (Threaded way, slower i guess because the need to clone of both static fields m and n, thats where I need help if its actually posible to do it without said fields).
+ Show Spoiler +

public class sumaMatConcurrente extends Thread{
public static float[][] m;
public static float[][] n;
private static float[][] res;
private static int filas;
private static int columnas; //column
private int fila; //row

//Constructor. Copy both matrices sent in params into the static fields.
public sumaMatConcurrente(float [][] mat1, float[][] mat2){
if(mat1.length!=mat2.length || mat1[0].length!=mat2[0].length){
System.exit(1);
}
else{
res=new float[mat1.length][mat1[0].length];
m=mat1.clone();
n=mat2.clone();
filas=mat1.length;
columnas=mat1[0].length;
}
}
//Second Constructor. Creates new objects with the row field initiated to the value of the row the thread will work on
private sumaMatConcurrente(int row){
fila=row;
}


//actually resolves the add of said row
public void run(){
for(int i=0;i<columnas;i++){
res[fila][i]=m[fila][i]+n[fila][i];
}
}

//method that start the add process, creating the threads and returning the resulting matrix.
public float[][] Suma() throws InterruptedException{
//Array to create threads
sumaMatConcurrente[] resultado=new sumaMatConcurrente[filas];

//Initialize row value and start the threads
for(int i=0;i<filas;i++){
resultado[i]=new sumaMatConcurrente(i);
resultado[i].start();
}
//join
for(int i=0;i<filas;i++){
resultado[i].join();
}
return(res);
}

}


class usasumaMatConcurrente (main class that uses previous one)
+ Show Spoiler +



public class usasumaMatConcurrente{

public static void main(String[] args) throws InterruptedException{
int filas=10000;
int columnas=10000;
float [][] m=new float[filas][columnas];
float [][] n;
for(int i=0;i<filas;i++){
for(int j=0;j<filas;j++){
m[i][j]=1.0f;
}
}
n=m.clone();
sumaMatConcurrente obj=new sumaMatConcurrente(m,n);
m=obj.Suma().clone();
}
}

"There's farmers and there's gamers, farmers get up early, gamers sleep in." Artosis
phar
Profile Joined August 2011
United States1080 Posts
November 21 2012 18:16 GMT
#3966
When posting code, please use
[code]
blocks with proper indentation so we can see it more easily.
Who after all is today speaking about the destruction of the Armenians?
Nobu
Profile Joined June 2010
Spain550 Posts
November 21 2012 18:54 GMT
#3967
On November 22 2012 03:16 phar wrote:
When posting code, please use
[code]
blocks with proper indentation so we can see it more easily.


Didn't know about code blocks! already fixed
"There's farmers and there's gamers, farmers get up early, gamers sleep in." Artosis
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
November 21 2012 20:10 GMT
#3968
On November 22 2012 03:54 Nobu wrote:
Show nested quote +
On November 22 2012 03:16 phar wrote:
When posting code, please use
[code]
blocks with proper indentation so we can see it more easily.


Didn't know about code blocks! already fixed

not quite, the block end must be [/code] ;P
Gold isn't everything in life... you need wood, too!
Nobu
Profile Joined June 2010
Spain550 Posts
Last Edited: 2012-11-21 20:19:05
November 21 2012 20:16 GMT
#3969
On November 22 2012 05:10 MisterD wrote:
Show nested quote +
On November 22 2012 03:54 Nobu wrote:
On November 22 2012 03:16 phar wrote:
When posting code, please use
[code]
blocks with proper indentation so we can see it more easily.


Didn't know about code blocks! already fixed

not quite ;P


Just failed on the last one. Fixed, this time for real T_T
"There's farmers and there's gamers, farmers get up early, gamers sleep in." Artosis
phar
Profile Joined August 2011
United States1080 Posts
November 21 2012 21:26 GMT
#3970
This "two separate constructors to create two functionally separate types of the same class" is a really confusing construct, try not to do that. Use a single class to wrap, and a separate class for your worker. Have your worker's constructor take in two single dimensional arrays to add, and don't be passing in the entire giant array around.

It's not clear to me why you're cloning the same array 4 times, and then cloning your answer. Why not just use one source array and add it to itself? Or are m & n supposed to actually be different? Finally, if you do want m & n to be identical, don't do n = m.clone(), create m & n the same way at the same time. It'll have marginally better cache performance.

It's also not clear to me why you're creating ten thousand threads. Are you running this on a stupidly large amount of cores?

That's all I got for the moment, may have a chance to look at this more later.
Who after all is today speaking about the destruction of the Armenians?
Nobu
Profile Joined June 2010
Spain550 Posts
Last Edited: 2012-11-21 22:03:41
November 21 2012 21:59 GMT
#3971
On November 22 2012 06:26 phar wrote:
This "two separate constructors to create two functionally separate types of the same class" is a really confusing construct, try not to do that. Use a single class to wrap, and a separate class for your worker. Have your worker's constructor take in two single dimensional arrays to add, and don't be passing in the entire giant array around.

It's not clear to me why you're cloning the same array 4 times, and then cloning your answer. Why not just use one source array and add it to itself? Or are m & n supposed to actually be different? Finally, if you do want m & n to be identical, don't do n = m.clone(), create m & n the same way at the same time. It'll have marginally better cache performance.

It's also not clear to me why you're creating ten thousand threads. Are you running this on a stupidly large amount of cores?

That's all I got for the moment, may have a chance to look at this more later.


I think i didnt explain myself well. First important thing, is that I have to use 2 classes to do the operation in the threaded way (one is supossed to have all the methods and stuff, and the other just main), and i cant mix them into a single class even if i could(would be easier imo). The purpouse of this classes is to compare the performance of concurrent vs non-concurrent classes.

That said, I put the 2 static float[][] fields, because I dont know a way (if possible) to add two matrices using threads and 2 classes, if i have the matrices in the non-concurrent class to start with. Therefore I came up with the static fields that stored said matrices, so i could access them from the run() method, and the res matrix to save the result of the add for that row.

For the cloning, m and n are supposed to be different(doesnt matter actually but in reality could be), and the ammount of threads its because we are supposed to create one thread per row. I set the dimensions of the matrices at 10k just to test if the higher the size, the faster the concurrent program ran compared to the non-concurrent.

The strange thing for me is that the concurrent way is slower than the other one, and the only reason I can think of is that, because I cloned m and n in the static fields, that adds a lot of load to the program, but as I said, i can't think of a way to implement run() without having the two matrices in a static field, and thats pretty much the question.

Thanks for the help anyways and im terrible at explaining myself T_T
"There's farmers and there's gamers, farmers get up early, gamers sleep in." Artosis
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-22 04:46:49
November 22 2012 01:09 GMT
#3972
I'm having issues with deserializing some json with C#.

Suppose this is a snippet of the json I'm being sent (repeated many times, but nothing else other than id/name):
[
{
"id":0,
"name":"N/A"
},
{
"id":1,
"name":"Annie"
},
{
"id":2,
"name":"Olaf"
}
]


If the top level was named, I'd do something like
    [DataContract]
public class ChampList
{
[DataMember(Name = "SOMENAME")]
public ElophantChamp[] ElophantChamps { get; set; }
}

[DataContract]
public class ElophantChamp
{
[DataMember(Name = "id")]
public int ID { get; set; }

[DataMember(Name = "name")]
public string Name { get; set; }

}


and then deserialize it by calling this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ChampList));
object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
ChampList jsonResults = objResponse as ChampList;


But in the case where there is no top level container object and I can't have blank datamember name, what do I do? I just get a null value if I leave the DataMember unnamed (i.e. leave it as [DataMember])
twitch.tv/cratonz
phar
Profile Joined August 2011
United States1080 Posts
November 22 2012 02:49 GMT
#3973
^ What json library? json.net?

On November 22 2012 06:59 Nobu wrote:
I think i didnt explain myself well. First important thing, is that I have to use 2 classes to do the operation in the threaded way (one is supossed to have all the methods and stuff, and the other just main), and i cant mix them into a single class even if i could(would be easier imo). The purpouse of this classes is to compare the performance of concurrent vs non-concurrent classes.
Yes, I understand why at least 2 classes are necessary. I'm advocating at least 3 classes, possibly more. Having your worker class also be your controller class is just overly confusing.

On November 22 2012 06:59 Nobu wrote:
That said, I put the 2 static float[][] fields, because I dont know a way (if possible) to add two matrices using threads and 2 classes, if i have the matrices in the non-concurrent class to start with. Therefore I came up with the static fields that stored said matrices, so i could access them from the run() method, and the res matrix to save the result of the add for that row.
Yea, try ditching the static access for each of your workers. Pass a single dimensional array representing ONLY the info that an individual worker needs, no more. Have the worker toss that info back to the main thread. I'm guessing you're not looking into future/callable/etc type solutions.

On November 22 2012 06:59 Nobu wrote:
For the cloning, m and n are supposed to be different(doesnt matter actually but in reality could be), and the ammount of threads its because we are supposed to create one thread per row. I set the dimensions of the matrices at 10k just to test if the higher the size, the faster the concurrent program ran compared to the non-concurrent.

The strange thing for me is that the concurrent way is slower than the other one, and the only reason I can think of is that, because I cloned m and n in the static fields, that adds a lot of load to the program, but as I said, i can't think of a way to implement run() without having the two matrices in a static field, and thats pretty much the question.

Thanks for the help anyways and im terrible at explaining myself T_T

If you're running this on a computer with 4 cores, 10,000 threads isn't exactly helping. Try reducing the number of workers to a more sane level and allocating work through a really simple task master.
Who after all is today speaking about the destruction of the Armenians?
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-22 04:49:59
November 22 2012 03:28 GMT
#3974
The one that involves:
Reference:
System.Runtime.Serialization

Directives:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx
twitch.tv/cratonz
tec27
Profile Blog Joined June 2004
United States3701 Posts
November 22 2012 05:08 GMT
#3975
I'd recommend you don't use the built-in JSON serializer, its pretty shitty and not very easy to do custom parsing like you want here. I think they were adding Json.NET in as the default serializer for MVC4/.NET 4.5, but I haven't kept up with .NET since I quit my last job. Anyway, I'd recommend you use that.

Then you could just do something like:
var array = JArray.parse(json);
var champs = array.Select(token => token.ToObject<ElophantChamp>());


Not sure that code would actually work, but its close to what it would need to be.
Can you jam with the console cowboys in cyberspace?
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-22 05:11:03
November 22 2012 05:10 GMT
#3976
I already have 99% of what I want deserialized coded (i.e. I have numerous other ones working fine). All I want is to know what tweak I need to do for this one piece.
twitch.tv/cratonz
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2012-11-22 05:18:19
November 22 2012 05:17 GMT
#3977
On November 22 2012 12:28 Craton wrote:
The one that involves:
Reference:
System.Runtime.Serialization

Directives:
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx


Use http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

It's a lot easier to use and also included in .net by default.

String json = GetTheJson();
List<Items> = JavaScriptSerializer.Deserialize<Items>(json);
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-22 06:01:58
November 22 2012 05:18 GMT
#3978
I asked a simple question, which was not "how can I do what I'm already 99% done with using a completely different package."

I even expressly said I only want to know what very minor thing I need to do with my existing code.
twitch.tv/cratonz
tec27
Profile Blog Joined June 2004
United States3701 Posts
Last Edited: 2012-11-22 05:51:24
November 22 2012 05:50 GMT
#3979
I'm pretty sure the answer is that you can't, because the DataContractJsonSerializer is shit, like I said. The interface it implements is designed for deserializing XML, not JSON, and thus doesn't contain methods for parsing top-level things that aren't objects. It would take you 20 seconds to install Json.NET and change your code to use it, the resulting code would be vastly cleaner, and you wouldn't be dependent on a shitty class that Microsoft's own library developers have clearly given up on using. Quit asking questions and then getting all uppity when people suggest better ways for you to do things.
Can you jam with the console cowboys in cyberspace?
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-22 05:56:02
November 22 2012 05:53 GMT
#3980
I wouldn't have to grumble over non-answers if they were actual answers.

It took three posts just to force an angry reply out of you that what I'm using MIGHT not be able to do what I want. Instead, you got up on your "look at how great this thing I prefer is, change all your code to suit my personal preference" why? "because I personally feel the thing you're using is shit, but I'm not going to bother actually trying to help you"

If you don't want people getting "uppity," then provide actual answers. Exponentially so when I came out and explicitly said all I want to know is what I have to tweak and then got the exact same kind of non-answer.
twitch.tv/cratonz
Prev 1 197 198 199 200 201 1031 Next
Please log in or register to reply.
Live Events Refresh
PiGosaur Monday
00:00
#46
PiGStarcraft236
SteadfastSC38
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft236
NeuroSwarm 147
Nina 136
ProTech85
CosmosSc2 43
Nathanias 41
SteadfastSC 38
StarCraft: Brood War
Artosis 781
Hyuk 470
NaDa 54
Sharp 36
Dota 2
monkeys_forever368
Counter-Strike
fl0m1044
taco 101
Super Smash Bros
hungrybox316
AZ_Axe83
PPMD44
Liquid`Ken8
Other Games
summit1g7182
shahzam1616
Day[9].tv847
C9.Mang0352
WinterStarcraft245
ViBE244
Maynarde150
ToD130
Organizations
Other Games
gamesdonequick833
BasetradeTV16
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• RyuSc2 43
• rockletztv 11
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22476
League of Legends
• Stunt236
Other Games
• Day9tv847
Upcoming Events
Afreeca Starleague
9h 30m
hero vs Alone
Royal vs Barracks
Replay Cast
23h 30m
The PondCast
1d 9h
WardiTV Summer Champion…
1d 10h
Clem vs Classic
herO vs MaxPax
Replay Cast
1d 23h
LiuLi Cup
2 days
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
2 days
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
BSL Team Wars
2 days
Team Hawk vs Team Dewalt
BSL Team Wars
2 days
Team Hawk vs Team Bonyth
SC Evo League
3 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
[ Show More ]
Maestros of the Game
3 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[BSL 2025] Weekly
3 days
SC Evo League
4 days
Maestros of the Game
4 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
4 days
Team Bonyth vs Team Sziky
BSL Team Wars
4 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
5 days
Replay Cast
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

CSLAN 3
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
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.