13

I was looking through some Objective C docs.. and got this :

UIGraphicsBeginImageContext : Creates a bitmap-based graphics context and makes it the current context.

Also, the same term is used in Robotlegs :

(http://www.adobe.com/devnet/actionscript/articles/intro-robotlegs-pt1.html) Context: Context is the bootstrapping mechanism that initializes dependency injection and the various core utilities that Robotlegs uses.

Dictionary meaning of context as i googled, doesnot seem to match the way it's used in programming :

con·text /ˈkäntekst/ Noun The circumstances that form the setting for an event, statement, or idea, and in terms of which it can be fully understood and assessed.

The parts of something written or spoken that immediately precede and follow a word or passage and clarify its meaning.

Anybody can throw some light pls!

V.

1 Answer 1

25

The circumstances that form the setting for an event, statement, or idea, and in terms of which it can be fully understood and assessed.

That's really not too far from the programming sense of the word. Context generally has to do with some kind of state that's necessary to perform an operation.

A graphics context is typically an object or structure that contains all the information needed to draw in a particular place. Graphics contexts are often maintained in a stack, and any drawing operations happen using the information in the context at the top of the stack. A graphics context could contain information like the buffer in which to draw, current pen size, drawing color, background color, transformation matrix, pen location, and so on.

Similarly, you could have a database context, a file context, an audio context... none of these things are specifically defined outside the scope of a given API, but they all mean the same thing -- the set of conditions needed to properly carry out operations in the system in question.

2
  • So, whatever information ( objects, instances ) already available when i start programming, are context objects/instances ?
    – Vishwas
    Apr 29, 2013 at 6:19
  • 4
    I suppose you could say that. The word often implies a single object or structure containing all the necessary state, or at least refers collectively to all the necessary state. For example, when a context switch happens in a multithreaded system, one thread's context (the collection of stack, registers, etc.) is replaced with that of another so that the new thread can start running from where it last stopped. So, whatever's available when your program starts is part of that process's context, but you probably wouldn't refer to them as "context objects".
    – Caleb
    Apr 29, 2013 at 6:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.