w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Nice way of accessing member variables based on a switch
Just encapsulate the switch: In the object's class, define GetMemberVariableAt(int) and move the switch in there. Then, have your client code ask for object.GetMemberVariableAt(someVariable). If you do this, it won't be all that important that you're using a nasty switch to get to the right member variable, because the switch will be internal to your object's implementation, not smeared across your code. And, you have the piece of mind that you can improve it later with minimal effort, switching to an array or whatever your mind (or your performance requirements, perhaps) desires. If you don't control the source code of the class of your object, you can still proxy it or put an adapter in front of it, and code to the proxy or adapter. The solution I am giving here is intended to ma

Categories : C++

Performance considerations with db.BlobProperty()
The minute you retrieve the entity, the blob is loaded from the datastore unless you do a projection query. You have a few options to avoid loading the BlobProperty until you need it. do a projection query and then only fetch the full entity when you need it. stick the BlobProperty in a Child entity (make the top level one the ancestor) and only fetch the property with a get, when you need it. Don't use a BlobProperty but stick it in GCS (Google CLoud Storage) and serve it from there. The last has the benefit that if you do no processing on the blob your appengine instance doesn't need to get involved with serving it (depending on what your requirements are of course)

Categories : Google App Engine

Javascript Delegation performance considerations
But, if bubbling is not stopped, events spawn and propagate through all the DOM tree, so there is the same resource consumption in the page using delegation or not. And, if the delegated handler has to perform check on the source of the event, it would be also more consuming... Events propagating through the DOM tree without any event listener associated, do not necessarily request browser memory usage. What does not request an action, may be not monitored at all. Modern browsers are highly optimized for better UI performance, and this type of memory waste would be the first issue to avoid in any elementary client. The problem is not the high number of events generated from a UI which propagate through the DOM tree, but all the event listeners that the browser must save in memory for

Categories : Javascript

Considerations for sqlite database performance in iOS
You have the transaction overhead once for each statement. Wrap all statements into a single transaction. Execute BEGIN/END manually, or just write them into your .sql file.

Categories : IOS

Header files inclusion and performance considerations c++
Run-time efficiency The sets of headers included or not included really have no effect on the efficiency of the resulting application at run time. You should include the headers that declare the functions you use. If those headers provide inline function definitions, for example, then you may get some performance boost by comparison with (hypothetical alternative) headers that don't provide inline function declarations, but you still need to include the header so that is controlled by the people providing the headers. Compile-time efficiency I first assumed this was what you're after, in part because of the mention of header include guards which are a purely compilation-related issue. If the headers are set up with include guards, you can still improve efficiency of compilation (with

Categories : C++

Performance considerations using html elements on top of canvas
Yes, putting other DOM elements on top of a canvas element will reduce its performance. This is because the browser have to do extra clipping when updating canvas / painting. The canvas need to update 60 times per second to output to screen. If something is on top it needs to be clipped just as many times. If the DOM element is repainted as well will be browser dependent but the performance of the canvas element itself is reduced. Usually the DOM paints happens in a single thread (but is about to change for most major browsers) so if there is extra load on that thread it will affect everything else being drawn too. And there is the single-threading of JavaScript which is necessary to use to update canvas. If canvas has reduced performance than the script executing its changes (as well

Categories : Performance

Performance considerations of using an event based Timers vs Polling
The java.util.Timer effectively does what your colleague suggests (truth be told, in the end, there really aren't that many ways to do this). It maintains a collection of TimerTasks, and it waits for new activity on it, or until the time has come to execute the next task. It doesn't poll the collection, it "knows" that the next task will fire in N seconds, and waits until that happens or anything else (such as a TimerTask added or deleted). This is better overall than polling, since it spends most of its time sleeping. So, in the end, you're both right -- you should use a Timer for this, because it basically does what your coworker wants to do.

Categories : Java

accessing private member of member class
public class A { private int myMember; public int getMyMember() { return myMember; } public void setMyMember(int myMember) { this.myMember = myMember; } } public class B{ private A myA; public B() { myA = new A(); myA.setMyMember(0); int a = myA.getMyMember(); } }

Categories : Java

Limit of performance benefit gained in Python from using local variables instead of global variables?
As I understand it, that performance boost only applies when global variables are moved into a local scope of a function, as it improves their access time. Further breaking your code down into more functions won't provide any similar boost.

Categories : Python

Inheritance: accessing parent member
CAD is a completely new form, which you never show. The form that is on the screen is never changed. Instead of making CAD inherit from RAD, you should give it a field RAD form, and access the form through that field. You've also got a suspicious finalizer. It won't run when you expect it to, and when it does run, I suspect it won't do what you want it to. In particular, it isn't called as soon as you call Dispose. class CAD { RAT form; public CAD(RAT form) { this.form = form; // Now the CAD class maintains a reference to the form it is // supposed to change. This field can be used in other methods // when it is time to remove the extra controls and restore // the size, like so: // form.Size = new System.Drawing.Size(805, 300);

Categories : C#

accessing member of structure within a class
You have just defined struct. Try something like this - struct packet{ int x; u_int y; }test; and in your cpp, access your struct elements like this - foo_1.test.x

Categories : C++

Accessing each member in a class in Java like in struct in C
You should store your operation objects into a Map A map works with key/value, you put an id into the map, and you can retrieve the corresponding key. In your example, use the class Operation : public class Operation { public int stream; public int functi; public name; public int funcgroup; } and a map like this : Map<String, Operation> map = new HashMap<String, Operation>(); Operation operation = new Operation(0,0,"name5", 0); map.put("name5", operation); You can retrieve your Operation object with : Operation op = map.get("name5");

Categories : Java

MEX/Matlab: Accessing objectarray which is a member of another object
After calling mxGetProperty to get array of objects it is better to call into MATLAB to do the indexing on this array of objects. If bar_mx is the mxArray for bar object then foos_prop = mxGetProperty(bar_mx, 0, "foos"); // Gives foos property foos_i = mexCallMATLAB( ... [foos_prop, i]) call MATLAB function to get i'th foo You can combine your call to get i'th object along with calling of a method on that object. If you want to do the indexing in C++ you may need to call subsref function. It is easier to do mexCallMATLAB instead of creating the struct argument for subsref.

Categories : C

Accessing member from a static function - std::foreach
FooThe way I'd do it is with a function call instead of a static function. Use void processBlock(std::vector<double> &vect); And std::for_each(data.begin(),data.end(),std::bind(&Foo::processBlock,this,_1))

Categories : C++

accessing python object member that is a reserved keyword
You can use the getattr() function to retrieve it by name: getattr(options, 'pass'). When accessing attributes this way you have fewer restrictions on how they can be named, like in this case you can use a keyword.

Categories : Python

Python Help: Accessing static member variable from another class
The main problem seems to be that your main script is wrapped in a class. There's really no reason for this, and is quite confusing. if __name__ == "__main__": main_object = ValidateDriver() main_object.main(sys.argv[1:]) This should go outside the class definition

Categories : Python

Accessing the compiled code of a virtual member function
Here's a little bit of code that I hacked up, which (in g++ 4.6.3) appears to give the expected results. However, before I get downvotes simply because I'm trying to solve an unsolvable probel, this is absolutely relying on "undefined behaviour". Since the standard doesn't even go into how virtual methods are supposed to be implemented with regards to vptr, vtable, etc, there is no way that you can actually implement this without knowing what the compiler does - and of course, a new version, even in a minor revision, or using different compile options of compiler may change this (e.g. debug mode vs release mode could be different - but that would make it hard to mix debug and release or mix code compiled with old and new compilers) #include <iostream> using namespace std; class

Categories : C++

Java Homework Help (Accessing Static Member via Instance Reference)
You should actually not use the string temp. You should call it as String.format. To answer your question, it is confusing, since the call actually doesn't look at temp.

Categories : Java

Prevent users from accessing member pages by entering cached url
What you need to do is create a proper login system using something like a session. There are countless tutorials you'll find about this by googling "php login tutorial with session". Here is one of those results. At the heart of all of these are PHP Sessions, which allow you to store information for a specific client throughout their browser session. To understand sessions in php, here's a basic tutorial Let me know if these make sense or if you have any questions :)

Categories : PHP

"Access to the registry key 'Global' is denied" when accessing performance counters
I found the solution. Whereas various links around the Internet tell you to use the identity IIS APPPOOLDefaultAppPool, that is NOT the full story. That will only work if you are in fact assigning your applications to an app pool named "DefaultAppPool". This link at ServerFault has the answer. You must use the name of your app pool. In my case, the app pool's name was "staging", so the correct user was IIS APPPOOLstaging. Putting this user in the Performance Monitor Users group fixed my issue.

Categories : Asp Net

Accessing system performance data directly from the linux kernel
I think there are several files under /proc, such as /proc/stat, /proc/diskstats, /proc/net/*. For CPU performance information, using /proc/stat, the file format is defined in the file ./fs/proc/stat.c in Linux Kernel source code tree. For disk access information, using /proc/diskstats, the file format is defined in the file ./block/genhd.c in Linux Kernel source code tree, the function is diskstats_show(). For network related statistics, one can refer to files under /proc/net/. But I don't know how to calculate the bandwidth usage based on file under directory /proc/net.

Categories : Linux

Initializing member variables of a struct in c++
No. In the general case, they have unspecified values. If you don't like this behaviour, you can provide a constructor: struct A { double a; double b; A(): a(0.0), b(0.0) {} }

Categories : C++

Lambda captures and member variables
Member variables can never be captured by value. What's being captured by value is the implicit this pointer used to access them. Therefore, it's capturing a pointer by value, which means it captures this object (and its members) by reference.

Categories : C++

Accessing variables within a URL
I ammended this question through the quesry string having "&" the system thought it was the end of the querystring. I chnged this by encoding and decoding my urls with UrlEncode and UrlDecode

Categories : C#

How to use member variables with Interfaces and anonymous implementations
There is nothing like variable-overriding like method overriding in java. Name a new type for subclass, then you will get the "String Implementation", when you access through the subclass reference type. Access privilege protected only means we can access the variable in a subclass but not that it can be override. Even if you are using normal class instead of interface this won't work. When you refer using super class type, you only get the instance variables from super type and so on.... This example illustrates the first case: Example: public class Tester { public static void main(String arg[]) throws Throwable { Tester t = new Tester(); System.out.println(t.meth().s); // it prints "Old value" because your type is TestInter } private TestInter meth() {

Categories : Java

Protected member variables in abstract class?
I believe your problem might be else where. Change: void DoMagic() = 0; to: virtual void DoMagic() = 0; Also make sure you have a virtual destructor. virtual ~A( ) { } When you derive make sure you initialise var1 from the derived constructor before you use it. B::B( ) : var1( 0 ) { } As for design, I don't know the context, in some cases it's okay, but I try avoid it.

Categories : C++

Static final member variables vs. get methods
using getDisc() you can have one disc variable per object while static disc is shared across all the instances. If you have different disc value for every instance of class, then go for second approach. If you have same value which needs to be shared across all the instances of the class, then use the first approach By they way, you cannot do System.out.println(Config.getDisc());. You can't call a non-static method using class name

Categories : Java

Alternative to keyword mutable for member variables in C++
Alternative to keyword mutable for member variables in C++ If there was an alternative to mutable, then we wouldn't need the keyword. A* pAnotherPointer = const_cast<A*>(pPointer); - This is just removing the constness from a pointer, allowing you to call const methods on an object. The address is the same. The best (as juanchopanza suggested) is to make ClassEx::ClassFunction() non-const.

Categories : C++

Adding new member variables to python objects?
A similar example is given in the Python Docs. According to it, this notation is used for binding together a couple of named items. This is just what Python allows you to do.

Categories : Python

Accessing variables from outside of class
fr.php Notice the return $lang; $lang["W_TYPE"]["COMPLETE"] = "Completé"; $lang["W_TYPE"]["INCOMPLETE"] = "Incomplet"; $lang["W_TYPE"]["BO"] = "En attente"; return $lang; Other file Notice the $lang = require_once 'fr.php'; public function getCompletion($string = true) { $lang = require 'fr.php'; $x = $this->COMPLETION; if($string) { echo $lang["W_TYPE"]["COMPLETE"]; if($x==self::ORDER_COMPLETE) { return "<font class='jobComplete'>".$lang["W_TYPE"]["COMPLETE"]." &#x2713;</font>"; } elseif($x==self::INCOMPLETE) { return "<font class='jobIncomplete'>".$lang["W_TYPE"]["INCOMPLETE"]."...</font>"; } elseif($x==self::BACK_ORDER) { return

Categories : PHP

Accessing variables outside class
You should refactor your code. As you are saying, you can't do $movies->fetch() since it echoes the table. That's a sign of braking the Single Responsibility Principle. You should divide your function into two: one function that fetches (and returns) the data, and another one that takes data as a parameter and returns a table with the data. That way, you can reuse the first one when you want to get the values for the edit form. Since you have a procedural background, I'd recommend that you create a new class that represents a "movie" that has the required fields. Then, for each row in your table you should create an instance of that class and populate the fields, and ultimately return all those instances. Sorry for not posting any code at the moment, I realized that would have been e

Categories : Function

Accessing environment variables
Rails.env only gives you the value of ENV["RAILS_ENV"] or ENV["RACK_ENV"]. If none of them were set, it returns "development". The ENV object is provided by Ruby. For another way to access it, you might consider either implementing it by yourself, or using the figaro gem. Set environment variables in a YAML config. Then they can be accessed like this: Figaro.env.rails_relative_url_root

Categories : Ruby On Rails

C++ Is it correct to call class member variables "attributes"?
A class' attributes would translate to its members. A method is not the same as a member function in general. But "In object-oriented programming, a method is a subroutine (or procedure) associated with a class." - Wikipedia.

Categories : C++

Generic class for multiple actions with different member variables
What you describe sounds a lot like the combined functionality of using std::function and std::bind. Using these creates a callable function object that stores all of the arguments that need to be passed while allowing you to execute the call without knowing any specific details. It works with both member functions and free functions. You could change your Command class into a simple wrapper that describes the requirements. The example below does this using free functions. The Command class does not care about the arguments or their types. All it cares about is how the command itself is dispatched. #include <iostream> #include <functional> #include <string> class Command { public: Command(const std::string& name, const std::function<void()>& func)

Categories : C++

Why not static const references on class member variables?
Simply because there is no such type as a reference-to-member, only a pointer-to-member. From the various posts in SO about différences between pointers and references, I don't find any clue. A pointer-to-member has little to do with a pointer apart from its (slightly misleading) name, and the fact that, like a pointer, it refers to something else. There was never considered to be a compelling reason to add an analogous type that looked more like a reference. So is it possible to define some variable aliases inside the same class? No, there's no sensible way to do that. Also I don't know C++0x very much, so does C++0x offers a solution for this? No.

Categories : C++

JAXB not creating member variables and getters and setters
What makes this use case odd is that you have inheritance in your XML Schema between two types with mixed content. I think there is an XJC (and possibly spec) bug here, and as suggested by Puce you should enter a bug for it at the following link: https://java.net/jira/browse/JAXB/ XML Schema schema.xsd Here is a simpler XML schema that reproduces the same issue: <?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema" xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified"> <complexType name="b" mixed="true"> <sequence> <element ref="tns:bb"/> </sequence> </complexType&

Categories : Java

Is there a method in java that returns member variables of a class
You're talking about reflection. Have a look at Class.getFields(): http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html See also: http://forgetfulprogrammer.wordpress.com/2011/06/13/java-reflection-class-getfields-and-class-getdeclaredfields/ There are quite a lot of fishhooks with reflection. Property-based access -- bean properties, of the form getX()/setX() or isX()/setX() -- may be a little better in helping you avoid unstable implementation internal of the class.

Categories : Java

Use specific block of memory for member variables of a class
You have two options: Overload the new operator for your class or Use placement new

Categories : C++

Properly handle disposable resources in member variables?
I hope you are looking for this: class Game : GameWindow, IDisposable { private bool _disposed; public void Dispose() { // If this function is being called the user wants to release the // resources. lets call the Dispose which will do this for us. Dispose(true); // Now since we have done the cleanup already there is nothing left // for the Finalizer to do. So lets tell the GC not to call it later. GC.SuppressFinalize(this); } /// <summary> /// Dispose client here /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!_disposed) { i

Categories : C#

Callback method cannot access member variables or instance
You need to pass a pointer to method, but the uvarupdate is pointer to function, these are different types. Pointer to a method contains implicit pointer to this of an instance, it doesn't fit into function-pointer. You need to pass this in some another way. If you do not change signature of the callback, you have to calculate an instance (this) somehow. If it can be determined from name parameter, well, it's easy. Another way is to create a trampoline for each instance you have. If there are only few instances, you can write a separate trampoline function for each instance. Creating trampolines dynamically (in run-time) is tricky and non-portable: in fact, you need to write some machine instructions into RAM so that they call your method with the correct this parameter. But that's also

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.