public static int getLenth(char[] t)
{
int i=0;
int count=0;
try
{
while(t[i]!='\0')
{
++count;
i++;
}
return count;
}
catch(ArrayIndexOutOfBoundsException aiobe)
{
return count;
}
}
This method returns length of charArray. But my question is, is there is some other "ways" to find the length of charArray without using this try, catch statements & all ??
Thanks in advance :)
This link says the HP Proliant DL 180 G5 server only supports Smart Array E200, E500, P400 and P800 controllers.
Can I use a Smart Array P410 instead?
Currently the server has only the default internal controller, I need an additional one for better performance and to support additional drives (the default controller only supports 4, with a Smart Array controller all 8 bays can be used). The disks are SATA ones.
It seems like a large number of security groups have been deleted from the organization's AD.
i was able to find the tombstones but i see there 1400 objects from the last 180 days and i know for certain that the important groups which have been deleted, have been deleted somewhere between yesterday's night and now.
Is there a way, maybe by using power shell to extract the names of all objects which have been deleted through out the night?
Thanks in advance
Itai
I'm making a game that invloves a tire moving through terrain that is generated randomly over 1000 points. The terrain is always a downwards incline like so:
The actual box2d terrain extends one screen width behind and infront of the circular character. I'm now at a stage where I need to add gameplay elements to the terrain such as chasms or physical objects (like the demo polygon in the picture) and am not sure of the best way to structure the procedural generation of the terrain and objects.
I currently have a very simple for loop like so:
for(int i = 0; i < kMaxHillPoints; i++) {
hillKeyPoints[i] = CGPointMake(terrainX, terrainY);
if(i%50 == 0) {
i += [self generateCasmAtIndex:i];
}
terrainX += winsize.width/20;
terrainY -= random() % ((int) winsize.height/20);
}
With the generateCasmAtIndex function add points to the hillKeyPoints array and incrementing the for loop by the required amount. If I want to generate box2d objects as well for specific terrain elements, I'll also have to keep track of the current position of the player and have some sort ofarrayof box2d objects that need to be created at certain locations.
I am not sure of an efficient way to accomplish this procedural generation of terrain elements with accompanying box2d objects. My thoughts are:
1) Have many functions for each terrain element (chasm, jump etc.) which add elements to be drawn to an array that is check on each game step - similar to what I've shown above.
2) Create an arrayof terrain element objects that string together and are looped over to create the terrain and generate the box2d objects. Each object would hold an arrayof points to be drawn and and arrayof accompanying box2d objects.
Any help on this is much appreciated as I cannot see a 'clean' solution.
Cross apply (and outer apply) are a very welcome addition to the TSQL language. However, today after a few hours of head scratching, I have found an simple issue which could cause big big problems. What would you expect from this statement ? select *
from sys.objects b
join sys.objects a
on a.object_id = object_id
No prizes for guessing SQL server errors with “Ambiguous column name 'object_id'”.
What would you expect from this statement ?
Select *
from sys.objects a
cross apply( Select *
from sys.objects b where b.object_id = object_id) as c
Surprisingly, perhaps, the result is a cross join of sys.objects. Well, what happened there ?
If you look at the apply statement, within the where clause, only one of the conditions is qualified with a table name. This meant that is has be interpreted as “b.object_id = b.object_id” causing the cross apply to have no join the the parent sys.objects table and causing the cross join.
The fix is , obviously, simple
Select *
from sys.objects a
cross apply( Select *
from sys.objects b where b.object_id = a.object_id) as c
So why no “Ambiguous column name ” error ? I’ve raised a connect item on this issue here.
If I have a plist which is structured like this:
Root Array
Item 0 Dictionary
City String New York
People Array
Item 0 String Steve
Item 1 String Paul
Item 2 String Fabio
Item 3 String David
Item 4 String Penny
Item 1 Dictionary
City String London
People Array
Item 0 String Linda
Item 1 String Rachel
Item 2 String Jessica
Item 3 String Lou
Item 2 Dictionary
City String Barcelona
People Array
Item 0 String Edward
Item 1 String Juan
Item 2 String Maria
Then what is the most efficient way of getting all the names of the people into one big NSArray?
I know I'm probably missing something easy, but I have a foreach loop and I'm trying to modify the values of the first array, and output a new array with the modifications as the new values.
Basically I'm starting with an array:
0 = A:B
1 = B:C
2 = C:D
And I'm using explode() to strip out the :'s and second letters, so I want to be left with an array:
0 = A
1 = B
2 = C
The explode() part of my function works fine, but I only seem to get single string outputs. A, B, and C.
I want to create an arrayof Dictionaries. But the array size is unknown. For integer, i used List to obtain the integer arrayof unknown size. But in the case of Dictionary, am not able to create a list of Dictionary. Is thr any wayz by which this can be done? Dictionary(int, String) paramList=null;I am want to create the arrayof paramList(above). I am using C Sharp.
Example array
$myArray[0] = array('23, null, 43, 12');
$myArray[1] = array('null, null, 53, 19');
$myArray[2] = array('12, 13, 14, null');
All nulls should be replaced with 0. I was hoping someone would have an efficient way of doing this, perhaps a built in PHP function that I am unaware of.
If I had an array like:
$array['foo'] = 400;
$array['bar'] = 'xyz';
And I wanted to get the first item out of that array without knowing the key for it, how would I do that? Is there a function for this?
Example array
$myArray[0] = array('23, null, 43, 12');
$myArray[1] = array('null, null, 53, 19');
$myArray[2] = array('12, 13, 14, null');
All nulls should be replaced with 0. I was hoping someone would have an efficient way of doing this, perhaps a built in PHP function that I am unaware of.
For example:
In Perl:
@array = (1,2,3);
system ("/tmp/a.sh @array" );
In my shell script, how do I handle this array in shell script? How do I handle the shell script to receive the arguments, and how do I use that array variable in shell script?
Can you please tell me how to store an array in session and how to retrieve that array from session?
I am trying to store one arrayof type Double and assigning values of the same type but it is showing me an error so please can anyone tell me how to assign values to the array which is in session?
Thank You
This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name as a string by using expression trees. Here is the method. public static string GetName<T>(Expression<Func<T>> e)
{
var member = (MemberExpression)e.Body;
return member.Member.Name;
}
And here is how you can use it.
string...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.
This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name as a string by using expression trees. Here is the method. public static string GetName<T>(Expression<Func<T>> e)
{
var member = (MemberExpression)e.Body;
return member.Member.Name;
}
And here is how you can use it.
string...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.
Is there a language where collections can be used as objects without altering the behavior?
As an example, first, imagine those functions work:
function capitalize(str)
//suppose this *modifies* a string object capitalizing it
function greet(person):
print("Hello, " + person)
capitalize("pedro")
>> "Pedro"
greet("Pedro")
>> "Hello, Pedro"
Now, suppose we define a standard collection with some strings:
people = ["ed","steve","john"]
Then, this will call toUpper() on each object on that list
people.toUpper()
>> ["Ed","Steve","John"]
And this will call greet once for EACH people on the list, instead of sending the list as argument
greet(people)
>> "Hello, Ed"
>> "Hello, Steve"
>> "Hello, John"
I want to map out a 2D arrayof depth elements for the fragment shader to use to check depth against to create shadows. I want to be able to copy a float array into the GPU, but using large uniform arrays causes segfaults in openGL so that is not an option. I tried texturing but the best i got was to use GL_DEPTH_COMPONENT
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT, GL_FLOAT, smap);
Which doesn't work because that stores depth components (0.0 - 1.0) which I don't want because I have no idea how to calculate them using the depth value produced by the light sources MVP matrix multiplied by the coordinate of each vertex.
Is there any way to store and access large 2D arrays of floats in openGL?
I have a GameObject (RoomOrganizer in the picture below) with a "RoomManager" script, and one or more child objects, each with a 'HasParallelagram' component attached, likeso:
I've also got the following in the aforementioned "RoomManager"
void Awake ()
{
Rect tempRect;
HasParallelogram tempsc;
foreach (Transform child in transform)
{
try
{
tempsc = child.GetComponent<HasParallelogram>();
tempRect = tempsc.myRect;
blockedZoneList.Add(new Parallelogram(tempRect));
Debug.Log(tempRect.ToString());
}
catch( System.NullReferenceException)
{
Debug.Log("Null Reference Caught");
}
}
}
Unfortunately, attempting to assign tempRect = tempsc.myRect causes a null pointer at run time.
Am I missing some crucial step? HasParallelgram is an empty script with a public Rect set in the editor and nothing else.
What's the proper way to get a child's component?
I have a baseClass where I do not want public setters. I have a load($id) method that will retrieve the data for that object from the db.
I have been using static class methods like getBy($property,$values) to return multiple class objects using a single database call. But some people say that static methods are not OOP.
So now I'm trying to create a baseClassCollection that can do the same thing. But it can't, because it cannot access protected setters. I don't want everyone to be able to set the object's data. But it seems that it is an all-or-nothing proposition. I cannot give just the collection class access to the setters.
I've seen a solution using debug_backtrace() but that seems inelegant. I'm moving toward just making the setters public.
Are there any other solutions? Or should I even be looking for other solutions?
I have a 2D-Array representing my world. I want to divide this huge thing into smaller chunks to make collision detection easier.
I have a Chunk class that consists only of another 2D Array with a specific width and height and I want to iterate through the world, create new Chunks and add them to a list (or maybe a Map with Coordinates as the key; we'll see about that).
world = new World(8192, 1024);
Integer[][] chunkArray;
for(int a = 0; a < map.getHeight() / Chunk.chunkHeight; a++)
{
for(int b = 0; b < map.getWidth() / Chunk.chunkWidth; b++)
{
Chunk chunk = new Chunk();
chunkArray = new Integer[Chunk.chunkWidth][Chunk.chunkHeight];
for(int x = Chunk.chunkHeight*a; x < Chunk.chunkHeight*(a+1); x++)
{
for(int y = Chunk.chunkWidth*b; y < Chunk.chunkWidth*(b+1); y++)
{
// Yes, the tileMap actually is [height][width] I'll have
// to fix that somewhere down the line -.-
chunkArray[y][x] = map.getTileMap()[x*a][y*b];
// TODO:Attach to chunk
}
}
chunkList.add(chunk);
}
}
System.out.println(chunkList.size());
The two outer loops get a new chunk in a specific row and column. I do that by dividing the overall size of the map by the chunkSize.
The inner loops then fill a new chunkArray and attach it to the chunk. But somehow my maths is broken here.
Let's assume the chunkHeight = chunkWidth = 64.
For the first Array I want to start at [0][0] and go until [63][63]. For the next I want to start at [64][64] and go until [127][127] and so on. But I get an out of bounds exception and can't figure out why.
Any help appreciated!
Actually I think I know where the problem lies:
chunkArray[y][x] can't work, because y goes from 0-63 just in the first iteration. Afterwards it goes from 64-127, so sure it is out of bounds.
Still no nice solution though :/
EDIT:
if(y < Chunk.chunkWidth && x < Chunk.chunkHeight)
chunkArray[y][x] = map.getTileMap()[y][x];
This works for the first iteration... now I need to get the commonly accepted formula.
I understand that from other answers, Arrays and Vectors are the best choices. Many on SE claim that Linked Lists and Maps are bad for video game programming.
I understand that for the most part, I can use Arrays. However, I don't really understand exactly when to use Vectors over Arrays.
Why even use Vectors? Wouldn't it be best if I simply always used an Array, that way I know how much memory my game needs?
Specifically my game would only ever load a single "Map" area of tiles, such as Map[100][100], so I could very easily have an arrayof GameObjectContainer GameObjects[100][100], which would reserve an entire map's worth of possible gameobjects, correct?
So why use a Vector instead? Memory is quite large on modern hardware.
With the advent of smart pointers, is it a sign of poor design if I see objects are deleted? I'm seeing some software components in our product that people are still doing this. This practice strikes me as un-idiomatic, but I need to be sure this is the industry consensus. I'm not starting a crusade but it'd be nice to be prepared theory wise.
Edit: legit uses of delete, Klaim mentioned the object pool use case. I agree.
Bad examples of using delete, I am seeing many new's in constructor or start() and corresponding delete's in the destructor or stop(), why not use scoped_ptr? It makes the code cleaner.
Turned out, this question is not easy to formulate for me, but let's try.
In Android, pretty much any UI object depends on a Context, and has defined lifetime. It also can destroy and recreate UI objects and even whole application process at any time, and so on. This makes coding asynchronous operations correctly not straightforward. (and sometimes very cumbersome) But I never have seen a real explanation, why it's done that way? There are other OSes, including mobile OSes (iOS, for example), that don't do such things. So, what are the wins of Android way (Activities & Contexts)? Does that allow Android applications to use much less RAM, or maybe there are other benefits?